Anonymous binary class names

I have the following problem:

1) There is some abstract class A with several anonymous subclasses stored in static fields of A. There is a circular relationship between two anonymous subclasses. The code for this abstract class is similar to the following:

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
        }
    };
}

2) Class A instances refer to other objects that are used in serialization. There are some objects that are pre-serialized by developers and then included in the release as binary data.

A . , java-. .class, , , A, _1, _2 _3, A $1, A $2 A $3 , .class , , , A, _1, _2 _3, A $2, A $3 A $1 . - pre-serialized , - .

- java- JVM, , ? JLS , , "$" - - .

, , "" , , . , , , , .

+3
3

, , , , Java , _2 _1. , , , Java , (, , , ).

, . ?

+1

? , :

  • , ... , - !; -)
  • - , ( , , ). , , Java, . .

, , , , - , . , , , , , , ! , ( ), ( ).

+4

?

I believe that you can read data without relying on anonymous class names in the current code, overriding ObjectInputStream.readClassDescriptor. Replace the handle of the "compatible" class. There are no guarantees that will work, but it may be worth a try if your details are important.

+1
source

Source: https://habr.com/ru/post/1719277/


All Articles