Conditional Compilation + Inner Class Oddity

Jeremy Manson jeremymanson at
Thu Oct 24 11:34:29 PDT 2013

Hi folks,

We've found an oddity with conditional compilation and inner classes, and
was wondering if there was an explanation for it.  In the following code,
whether Test$1 is generated depends on whether Test$NestedClass is private
or not.  I don't think this violates the spec (given that you don't have to
generate Test$1 at all), but it is deeply curious:

public class Test {
  private static final boolean DBG = false;

  static class NamedClass {
    int abc;

  public void method() {
    if (DBG) {
      Thread t = new Thread(new Runnable() {
          @Override public void run() {
    NamedClass nc = new NamedClass();

(Note that in javac 7, Test$1 has run() and <init> methods without Code
attributes, which violates the spec.  In javac 8, Test$1 doesn't have run()
or <init> methods at all, which is probably fine (albeit odd).  Perhaps the
fix should be backported?)

Presumably, there is some method to the decision as to whether to generate
Test$1, but I have no idea what it is.

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the compiler-dev mailing list