JDK-7086595 : Error message bug: name of initializer is 'null'
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-09-02
  • Updated: 2014-07-25
  • Resolved: 2012-02-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4Fixed 8 b08Fixed
Related Reports
Relates :  
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
13-09-2011

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