8 comments
Comment actions Permalink

Hi Peter

Is the "infer nullity" feature also deprecated? As I understand helps the configuration of check and assert methods to infere nullity. Now it is harder for IDEA to infer @NotNull and @Nullable.
What do you think?

Cheers
Stefan


Just for cross linking:
http://youtrack.jetbrains.com/issue/IDEA-35808

0
Comment actions Permalink

"Infer Nullity" should work as expected. Do you experience any issues with it?

0
Comment actions Permalink

It works fine but without ability to configure the assert methods I guess it's harder to infere @NotNull. Or am I wrong?

0
Comment actions Permalink

Infer Nullity doesn't currently use that information. And you have the ability to configure assert methods using contracts.

0
Comment actions Permalink

You mean in a method where I use SomeAsserter.assertNotNull(aParameter) I can add a contract like (I don't know the syntax) @Contract(aParameter -> fail)?

Or do you have an example how I extend the following?

public void method(String aParameter) {
     SomeAsserter.assertNotNull(aParameter);
     // more code
}

0
Comment actions Permalink

The simplest way would be to annotate aParameter as @NotNull and remove SomeAsserter. It might also get you runtime assertions generated by IDEA.

You can annotate SomeAsserter.assertNotNull method by @Contract("null->fail"), this will make IDEA's highlighting know that in "more code" part aParameter is not-null. If you have access to SomeAsserter source code, you can do this annotation directly there. If it's in a library, go to the declaration of assertNotNull and choose "Add Contract" intention from Alt+Enter menu and enter null->fail there.

0
Comment actions Permalink

Hi Peter

Ok, now I understand your approach. Instead of configuring check/assert methods I annotate them directly with contracts. I'll try that out.

Thanks alot for the help
Stefan

0

Please sign in to leave a comment.