Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7160907

Regression: Failed to compile if enumType is null in Enum valueOf

    Details

    • Subcomponent:
    • Introduced In Build:
      b34
    • Introduced In Version:
      8
    • CPU:
      generic
    • OS:
      generic

      Description

      In Enum valueOf, if enumType is null, it failed to compile.


      import java.util.*;
      import java.lang.reflect.*;

      public class TestEnum {

         public static void main(String[] args) {
              try {
                   Colour02 test = Enum.valueOf(null, "BLUE");
                   System.out.println("Test Fail");
              } catch(NullPointerException e) {
                 System.out.println("Test Pass");
             }
         }

      }

      enum Colour02 {
           RED,YELLOW,GREEN,BLUE,PINK,BLACK;

      }


      javac result:

      javac TestEnum.java
      TestEnum.java:8: error: incompatible types: invalid inferred types for T#1
                   Colour02 test = Enum.valueOf(null, "BLUE");
                                               ^
          reason: inferred type does not conform to upper bound(s)
            inferred: T#2
            upper bound(s): Colour02,Enum<T#2>
        where T#1,T#2 are type-variables:
          T#1 extends Enum<T#1> declared in method <T#1>valueOf(Class<T#1>,String)
          T#2 extends Colour02
      1 error

        Attachments

          Activity

            People

            • Assignee:
              mcimadamore Maurizio Cimadamore
              Reporter:
              amlu Amy Lu
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: