Export to GitHub

jarjar - issue #58

jarjar should rename inner $SwitchMap$com$foo$MyEnum class generated by enum switch


Posted on Feb 13, 2013 by Happy Kangaroo

In Java 1.6.0_37, any code that uses a switch on an enum type (say, com.foo.MyEnum) generates an inner class named $SwitchMap$com$foo$MyEnum:

http://www.benf.org/other/cfr/switch-on-enum.html

When repackaging a jar from com.foo to com.bar, jarjar does not rename the generated inner class (probably because it's prefixed with $SwitchMap$ and the namespace is separated by $).

This doesn't cause any bugs (the code continues to work just fine), but it definitely raised alarm for me when I ran jarjar on Google libphonenumber 5.2 to repackage it into a private namespace, and I still found instances of com.google in the resulting jar.

See attached repro case, which repackages a com.facebook.jarjartest.JarJarTest class to com.zombo.JarJarTest.

You can unzip jarjartest-out.jar and look at the strings in com/zombo/JarJarTest.class and com/zombo/JarJarTest$1.class (which is the generated $SwitchMap$ inner class) to confirm they are not renamed.

For example, before repackaging with jarjar:

% strings com/facebook/jarjartest/*.class | grep SwitchMap )$SwitchMap$com$facebook$jarjartest$MyEnum )$SwitchMap$com$facebook$jarjartest$MyEnum

And after:

% strings com/zombo/*.class | grep facebook
)$SwitchMap$com$facebook$jarjartest$MyEnum )$SwitchMap$com$facebook$jarjartest$MyEnum

I would expect the resulting inner class to be renamed to $SwitchMap$com$zombo$MyEnum.

Attachments

Status: New

Labels:
Type-Defect Priority-Medium