Community
Participate
Working Groups
Created attachment 282475 [details] Java project reproducing the issue Hello, Let's say you have a method which returns an array of objects. If you call this method and get an element of the array, you will be able to call a method of the element, even though it may be null. However, you are not allowed to pass the element to a method if it requires a non-null parameter. I think this behavior is not consistent: either the analyzer considers that it is not required to check that the element is null, in which case I should be able to pass the element to the method ; or the analyzer requires a null check, in which cas I should not be able to call a method of the element. I have attached an Eclipse JDT project which reproduces this issue. Tested with JDK 1.7, with null analysis enabled in project configuration. Best regards, Andy
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.
Created attachment 288459 [details] Java project reproducing the issue (Eclipse 2022-03)
The issue is still reproduced with Eclipse 2022-03. I have updated the Java project so that it works on this Eclipse version.
I checked your code and it works mostly fine for me. BTW analysis does not work unless you are on Java 8 or above. The @NonNullByDefault does not make the array values NonNull by default. Only the Array itself. The array values are not "marked" which is different than marked nullable. Because the values of the array are undefined you get weird behavior. It is like in legacy mode (e.g. `NonNullbyDefault({})` ) so I guess it allows method chaining. That is `createArray()[0]` does not have a Nullable type so you can call methods on it however if you pass it around there is problem because the type does not match as printValue requires `@NonNull Integer` and not `missing_annotation Integer`. An easy fix is to do: private static @Nullable Integer [] createArray() { return new @Nullable Integer[] { 5, 3, null }; } Notice how I had to mark the array twice. Or you can actually specify it in `@NonNullByDefault({Location.ARRAY_CONTENTS, ...)`.