lw-lin / jarjar

Automatically exported from code.google.com/p/jarjar
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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.

Original issue reported on code.google.com by bgertzfi...@gmail.com on 13 Feb 2013 at 6:49

Attachments: