Friday, June 4, 2010

My first Eclipse bug

I filed my first Eclipse bug recently:

Bug 314830 - [JDT/core/compiler]
Switching on a null expression doesn't always throw NullPointerException

The person to which this bug is assigned made no mentions about it being specific to any version, so presumably this affects all current versions of Eclipse.

The essence of the bug is that due to overly aggressive optimizations on the part of Eclipse compiler, the following code does not throw NullPointerException.
java.math.RoundingMode x = null;
switch(x) {};

switch((Integer) null) {};

switch((Character) null) {
   default: System.out.println("I've got sunshine!");
This is a violation of JLS 14.11 The Switch Statement.
        switch ( Expression ) SwitchBlock

When the switch statement is executed, first the Expression is evaluated. If it evaluates to null, a NullPointerException is thrown and the entire switch statement completes abruptly for that reason.

See also: - Eclipse bug? Switching on a null with only default case

No comments:

Post a Comment