Skip to content

Unexpected errors from contract checking with !null return value #1444

Closed

Description

@marcphilipp

We're facing a similar issue to #1440 in the junit-framework build.

In our case, the contract is defined like this:

@Contract("null, _ -> fail; !null, _ -> param1")
public static <T> T notNull(@Nullable T object, String message) throws PreconditionViolationException {
	condition(object != null, message);
	return object;
}

... and use like this in a @NullMarked package:

public class DynamicContainer {

	final Stream<? extends DynamicNode> children;

	DynamicContainer(DefaultConfiguration configuration) {
		this.children = Preconditions.notNull(configuration.children, "children must not be null");
	}

	// ...
}

The notNull method is used ~500 times in the codebase and this is the only occurrence where 0.13.0 fails. Maybe it's due to configuration.children being generic with a wildcard (@Nullable Stream<? extends DynamicNode>)?

Activity

  1. msridhar commented on Jan 24, 2026

    @msridhar
    Contributor

    Hi @marcphilipp thanks for the report. What warning are you getting? I think this may not be related directly to the CheckContracts=true flag. Can you see if you still get the warning after removing that flag?

  2. msridhar commented on Jan 24, 2026

    @msridhar
    Contributor

    I dug in a bit and reproduced the error, and it's not related to contracts. It's a bug in our generic method call inference, which I guess was introduced in 0.13.0. Will look into this.

  3. msridhar commented on Jan 25, 2026

    @msridhar
    Contributor

    @marcphilipp would it be helpful to you if we cut a release with the fix for this issue? Please let us know. I check and with this fix, junit-framework compiles successfully. Thanks!

  4. added a commit that references this issue on Jan 25, 2026
    c27f3f4
  5. marcphilipp commented on Jan 25, 2026

    @marcphilipp
    Author

    There's no rush on our end but we'd certainly update right away if you do cut a release.

  6. msridhar commented on Jan 27, 2026

    @msridhar
    Contributor

    @marcphilipp we just put out NullAway 0.13.1 with the fix for this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions