United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 7086595 Error message bug: name of initializer is 'null'
7086595 : Error message bug: name of initializer is 'null'

Details
Type:
Bug
Submit Date:
2011-09-02
Status:
Closed
Updated Date:
2012-02-24
Project Name:
JDK
Resolved Date:
2012-02-24
Component:
tools
OS:
generic
Sub-Component:
javac
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
8

Related Reports
Backport:

Sub Tasks

Description
An error message that is supposed to print a method name instead prints 'null' when the error occurs inside of an initializer block.

public class InitializerError {

  int foo() {
    String s = "x";
    String s = "y";
  }

  static int bar() {
    String s = "x";
    String s = "y";
  }

  {
    String s = "x";
    String s = "y";
  }

  static {
    String s = "x";
    String s = "y";
  }

}

Output:

InitializerError.java:5: error: s is already defined in foo()
    String s = "y";
           ^
InitializerError.java:10: error: s is already defined in bar()
    String s = "y";
           ^
InitializerError.java:15: error: s is already defined in null
    String s = "y";
           ^
InitializerError.java:20: error: s is already defined in null
    String s = "y";
           ^
4 errors

In javac 6, the error message was different, but also bad -- it used an empty string as the method name.

                                    

Comments
SUGGESTED FIX

A webrev of this fix is available at the following URL:
http://hg.openjdk.java.net/jdk8/tl/langtools/rev/ed338593b0b6
                                     
2011-09-13
EVALUATION

Symbol.location() returns null if a symbol is defined in a static/instance initializer.
                                     
2011-09-02



Hardware and Software, Engineered to Work Together