Skip to content

filtering JAVAC.SYNTHCLASS

Evgeny Mandrikov edited this page Mar 12, 2017 · 9 revisions

This page discusses a not yet available feature!

Description

Synthetic class have no direct relationship to the classes defined in source code and are created by the compiler for technical reasons.

For example switches on enums when compiled with javac results in a synthetic class which holds a "switch map" to map the actual enum ordinals (which may change if the enum is modified) to constants int values which are used in the lookupswitch instruction. Note that javac 1.5.0_22 marks only field with map as synthetic, but not a class. Also note that ECJ places "switch map" and synthetic method for its initialization into the same class instead.

Filtering

Synthetic classes are completely removed.

Source Example

This results in instructions partial coverage of switch statement, because static initializer with uncovered exception handler in generated class refers to it:

class Fun {
    enum E {
        A, B
    }

    void fun(E e) {
        switch (e) {
            case A: ... ;
            default: ... ;
        }
    }

    public static void main(String[] args) {
        fun(E.A);
        fun(E.B);
    }
}

Bytecode Pattern

There are two ways to mark synthetic classes:

  • ACC_SYNTHETIC bit in the access_flags field
  • Synthetic class attribute