title: Anonymous class binary names
body: <p>I have the following problem:</p>
  
  <p>1) There is some abstract class A with several anonymous subclasses stored in the static fields of A. There is circular dependency between two of the anonymous subclasses. The code of that abstract class is similar to following:</p>
  
  <pre><code>class A implements Serializable
  { 
      public static final A _1 = new A() {
          public A foo()
          {
              return _2;
          }
      };
  
      public static final A _2 = new A() {
          public A foo()
          {
              return _1;
          }
      };
  
      public static final A _3 = new A() {
          public void bar()
          {
              // do something
          }
      };
  }
  </code></pre>
  
  <p>2) Instances of class A is referenced by other objects which are used in serialization. There are some objects which are pre-serialized by developers and then included into release as binary data.</p>
  
  <p>After some refactoring of A class binary names of anonymous subclasses was changed in the release builds. I think this may be due to difference of java compiler versions. From .class files made on my machine I can see that anonymous subclasses of A stored in _1, _2 and _3 fields have names A$1, A$2 and A$3, respectively, but from .class files taken from release build I can see that anonymous subclasses of A stored in _1, _2 and _3 fields have names A$2, A$3 and A$1, respectively. Due to this pre-serialized data became unusable and I need to fix this somehow.</p>
  
  <p>Are there any specifications for java compilers or JVM which will say what binary names I should expect for my anonymous classes? The JLS says that name of anonymous class should be name of enclosing class, "$"-sign and non-empty sequence of digits without setting any constraints on these sequences.</p>
  
  <p>I believe that I shouldn't rely on internal names of anonymous classes, I also know "proper" ways to fix that problem like generating pre-serialized data on the build server. Too bad we don't have much time for this now, so I want to know from where this naming difference comes, so I could fix this issue now.</p>