Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 526119

Summary: [1.8][null] JDT null analysis "Null type safety" warning methos which accept a generic Enum
Product: [Eclipse Project] JDT Reporter: Matthew DOnofrio <artist>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact: Stephan Herrmann <stephan.herrmann>
Severity: normal    
Priority: P3 CC: register.eclipse, stephan.herrmann
Version: 4.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows NT   
Whiteboard: stalebug

Description Matthew DOnofrio CLA 2017-10-17 00:18:11 EDT
I can't suppress this without explicitly adding a "@SuppressWarnings("null")" no matter how I try to annotate this.


---

package com.codespunk;

import org.eclipse.jdt.annotation.NonNullByDefault;

@NonNullByDefault
public class Test {

public enum SomeEnum {
   A
}

public static <E extends Enum<E>> String stringFromEnum(
   Enum<E> key)
{
   return "";
}

@SuppressWarnings("unused")
public static void main(
   String[] args)
{
   // Null type safety (type annotations): The expression of type
   // 'Test.SomeEnum' needs unchecked conversion to conform to
   // '@NonNull Enum<Test.@NonNull SomeEnum>', corresponding supertype is
   // 'Enum<Test.SomeEnum>'
   String a = stringFromEnum(SomeEnum.A);
}

}
Comment 1 Matthew DOnofrio CLA 2017-10-17 07:14:56 EDT
This is causing a LOT of warnings for me. Is there a way that I can disable this one warning across an entire project for now until this is fixed?
Comment 2 Till Brychcy CLA 2017-10-17 07:51:21 EDT
change the parameter of stringFromEnum:

public static <E extends Enum<E>> String stringFromEnum(E key)
{
   return "";
}
Comment 3 Stephan Herrmann CLA 2017-10-17 08:16:46 EDT
Could be as easy as implicitly marking the type argument in "extends Enum<SomeEnum>" as @NonNull, viz in ClassScope.connectEnumSuperclass()?

Plus similar treatment when reading a binary enum.

We should double check whether all references to that type parameter meet the criteria for nonnull. 
- Explicit use happens only in Enum.compareTo(E) and Enum.getDeclaringClass()
- implicit methods valueOf() and values() already have special treatment.

It looks so simple, feels like I'm missing s.t. :)
Any other usage of Enum's type parameter?
Comment 4 Eclipse Genie CLA 2020-04-18 07:35:44 EDT
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.