Community
Participate
Working Groups
Created attachment 286800 [details] Two examples of problematic code and two examples of accepted workarounds Overview: If 'Annotation-based null analysis' is enabled in 'Errors/Warnings', and a switch expression assigned to a field yields null in a method with a @Nonnull return value (even if the assignment does not impact the return value of the method in any way), the following will be given (severity depends on the 'Violation of null specification' setting): "Null type mismatch: required '@Nonnull <method return type>' but the provided value is null" Steps to reproduce: 1. Enable 'Annotation-based null analysis' in 'Errors/Warnings' 2. Ensure 'Violation of null specification' in 'Errors/Warnings' is above 'Ignore' 3. Create or override[1] a method annotated with @Nonnull 4. Create a Java 14 (JEP 361) switch expression and assign it to a field (the field being assigned to and the value being switched are irrelevant) var field = switch(switched) {} 5. In one of the cases (can also be default, yield null case "foo" -> null; default -> null; Actual results: The case will be marked as "Null type mismatch: required '@Nonnull <method return type>' but the provided value is null" Expected results: The case is not marked unless it is returned/causes the return value to be null. Build Date & Hardware: Build id: 20210612-2011 JDT version: org.eclipse.jdt.feature.group=3.18.800.v20210611-1600 System: Debian Bullseye/testing JRE/JDK: OpenJDK Runtime Environment AdoptOpenJDK-16.0.1+9 Attached is a sample of erroneous code, and workarounds that effectively accomplish the same thing. [1] 'Inherit null annotations' in 'Errors/Warnings' must also be enabled in case of overriding
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.
This problem still occurs in 2023-03 (4.27.0)
Ditto for 2023-06 (4.28.0)