I'm adding obfuscation via proguard/maven to a java application as we prepare it for distribution. During the process, it errors out with:
Note: ...eventlib.EventManager accesses a declared method 'getHandlerList()' dynamically
It then lists a dozen classes with that method with Maybe this is... and it recommends using -keep to avoid the problem.
When I do add -keep public class my.package.info.eventlib.HandlerList { *; } to the build process, the error goes away, but I see the following notices:
[proguard] Note: the configuration keeps the entry point 'events.TransactionEvent { TransactionEvent(my.package.info.inventory.Inventory,my.package.info.inventory.Inventory$TransactionType,my.package.info.inventory.ItemDefinition,short); }', but not the descriptor class 'my.package.info.inventory.Inventory'
When I run the application, it errors out with an NPE (which it doesn't do when run without obfuscation):
Caused by: java.lang.NullPointerException
at java.util.EnumMap.<init>(EnumMap.java:113)
at my.package.info.eventlib.HandlerList.<init>(Unknown Source)
at my.package.info.events.CollisionEvent.<clinit>(Unknown Source)
It's all tied to the events. How can I resolve this without telling proguard to keep everything tied to them?
Here's a full example of the original error: http://pste.me/m9BsY/
The event system is based on lahwran's fastevents
ProGuard notes that your code accesses a method dynamically, but it can't figure out which method it is precisely. If it renames or even removes the method, the reflection in your code will fail, so you need to keep the right method(s). Maybe you want to keep all of the listed candidates:
-keepclassmembers class * {
*** getHandlerList();
}
See the ProGuard documentation > Troubleshooting > Note: ... accesses a field/method '...' dynamically
ProGuard also notes that your configuration preserves the constructor of a class, but not all of its argument types. For some types of reflection, you also need to preserve these argument types. It's more likely that you're just accidentally keeping the constructor by using a wildcard. That would be a bit sloppy, but harmless.
See the ProGuard documentation > Troubleshooting > Note: the configuration keeps the entry point '...', but not the descriptor class '...'
For solving the NullPointerException, you have to know what is happening in your code in HandlerList. You can let ProGuard preserve line numbers with
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
If the code or the library performs reflection, and the original class names are important, you may need to preserve them. E.g. if the names of the event classes matter:
-keep class my.package.info.events.*
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With