Bug 145732 - [1.5][compiler] Inconsistent behavior in ECJ code for enum types
Summary: [1.5][compiler] Inconsistent behavior in ECJ code for enum types
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-07 06:25 EDT by Tim Ellison CLA
Modified: 2006-09-11 10:45 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Ellison CLA 2006-06-07 06:25:55 EDT
Build 3.2RC4

When compiling an enum type with the Eclipse compiler for Java, the code for valueOf(String) apparently looks like this:

public static Type valueOf(String s)
{
   Type atype[];
   Type type1;
   for(int i = (atype = ENUM$VALUES).length; --i >= 0;)
      if(s.equals((type1 = atype[i]).name()))
         return type1;

   throw new IllegalArgumentException(s);
}

Assume the actual argument for 's' is null.

If the ENUM$VALUES is not empty the message s.equals(...) causes a NullPointerException; however, if the array is empty then the code falls through to explicitly throwing an IllegalArgumentException.

I would expect the behavior for a null argument to consistently throw a NPE for empty and non-empty enum types.
Comment 1 Philipe Mulet CLA 2006-06-07 07:56:16 EDT
Agreed, a NPE should occur in both cases.
Comment 2 Philipe Mulet CLA 2006-06-07 08:01:42 EDT
Also see bug 145746
Comment 3 Philipe Mulet CLA 2006-06-07 09:20:11 EDT
Added EnumTest#test131(disabled) and test132.
Comment 4 Philipe Mulet CLA 2006-06-07 11:32:44 EDT
Fixed along with change for bug 145746
Comment 5 Philipe Mulet CLA 2006-06-09 11:18:58 EDT
Released for 3.2.1
Fix also released for 3.3M1
Comment 6 Frederic Fusier CLA 2006-08-08 07:43:07 EDT
Verified for 3.3 M1 using build I20060807-2000.
Comment 7 David Audel CLA 2006-09-11 10:45:55 EDT
Verified for 3.2.1 using build M20060908-1655