Feature request: NullPointer with several objects in same source code line - easily spot the object being null

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Mar 6 00:24:30 PST 2013


On 03/06/2013 09:36 AM, Krystal Mo wrote:
> public class Foo {
>   public static int demo(boolean cond, String s1, String s2) {
>     return (cond ? s1 : s2).length();
>   }
> }
> 
> Foo.demo() would be compiled into:
> 
>   public static int demo(boolean, java.lang.String, java.lang.String);
>     flags: ACC_PUBLIC, ACC_STATIC
>     Code:
>       stack=1, locals=3, args_size=3
>          0: iload_0
>          1: ifeq          8
>          4: aload_1
>          5: goto          9
>          8: aload_2
>          9: invokevirtual #2                  // Method
> java/lang/String.length:()I
>         12: ireturn
>       LineNumberTable:
>         line 3: 0
>       LocalVariableTable:
>         Start  Length  Slot  Name   Signature
>                0      13     0  cond   Z
>                0      13     1    s1   Ljava/lang/String;
>                0      13     2    s2   Ljava/lang/String;
>       StackMapTable: number_of_entries = 2
>            frame_type = 8 /* same */
>            frame_type = 64 /* same_locals_1_stack_item */
>           stack = [ class java/lang/String ]

The alternative would be to aid bytecode info with the column position
in the original source file (we only have the line number), so that we
could point to the particular member access operator, ".". But this will
require massive coordinated change to JVM spec, javac, and the HotSpot
bci handling. I don't think it is bearable at this point, but maybe
something to have around as JEP?

-Aleksey.



More information about the hotspot-runtime-dev mailing list