Switch statement in source results in type$1.class being generated?

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Jul 12 14:26:03 UTC 2019


Hi David,
javac has been generating 'switchmap' classes for enum switched since 
JDK 5, I believe.

This example:

enum Foo { A, B; }

class TestSwitch {
    int m(Foo foo) {
       switch (foo) {
          case A: return 1;
          case B: return 2;
          default: return -1;
       }
    }
}

Generates the following classes:

Foo.class
TestSwitch.class
TestSwitch$1.class

Where TestSwitch$1.class is similar to the one you have shown. I can see 
this even on JDK 8.

So, I think you might have found a real issue - but I'm not sure that 
this specific synthetic class is the root cause of your problem, as this 
class has been there for a long time.

Maurizio

On 12/07/2019 09:30, Dávid Karnok wrote:
> Hi.
>
> As part of the outreach program, I'm testing the various JDK early 
> access builds with the library RxJava. Now that I can test JDK 13 and 
> JDK 14 by setting a version target in my IDE, I've come across a 
> strange compiler output not encountered with JDK 12 and prior 
> versions. Note that RxJava's source code uses Java 6 constructs only.
>
> One of the rules for RxJava development is that there should be no 
> anonymous inner classes used as it makes analyzing stacktraces with 
> all those $12.class difficult. When the project is compiled, we check 
> for the existence of such type$x.class output and fail the build if 
> found. This worked well up until JDK 12, but now JDK 13 and JDK 14 
> early accesses generate a couple of such $1.class files. As far as I 
> can tell, they are due to switch statements, for example:
>
> https://github.com/akarnokd/RxJava3_BuildMatrix/blob/master/src/main/java/io/reactivex/Observable.java#L14379 
>
>
>     switch (strategy) {
>       case DROP:
>         return f.onBackpressureDrop();
>       case LATEST:
>         return f.onBackpressureLatest();
>       case MISSING:
>         return f;
>       case ERROR:
>         return RxJavaPlugins.onAssembly(new 
> FlowableOnBackpressureError<T>(f));
>       default:
>         return f.onBackpressureBuffer();
>     }
>
> Creates Observable$1.class:
>
>     javap Observable$1.class
>
>     Compiled from "Observable.java"
>       class io.reactivex.Observable$1 {
>       static final int[] $SwitchMap$io$reactivex$BackpressureStrategy;
>       static {};
>     }
>
> Is this some kind of expected new artifact?
>
> -- 
> Best regards,
> David Karnok
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20190712/46617713/attachment.html>


More information about the compiler-dev mailing list