I used Proguard with Maven to masking my Java code.
I change all functions from anonymous declaration to Lambda expression0 but after compiling and running I get error
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - Exception in thread "AWT-EventQueue-0"
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - java.lang.BootstrapMethodError: call site initialization exception
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.lang.invoke.CallSite.makeSite(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.lang.invoke.MethodHandleNatives.linkCallSite(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at com.goodsoft.stockbox.chart.f.c.h.a(ChartWindowPanel.java:50208)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at com.goodsoft.stockbox.commons.f.h.a.b.n(BaseWindowController.java:269)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at com.goodsoft.stockbox.commons.f.h.a.b.a(BaseWindowController.java:30)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at com.goodsoft.stockbox.commons.f.h.a.b$1.m(BaseWindowController.java:164)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at com.goodsoft.stockbox.commons.b.c.d$3.c(InstrumentController.java:324)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.event.InvocationEvent.dispatch(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventQueue.access$500(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventQueue$3.run(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventQueue$3.run(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.security.AccessController.doPrivileged(Native Method)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventQueue.dispatchEvent(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
2017-sty-20 08:53:46,289 ERROR [AWT-EventQueue-0] - at java.awt.EventDispatchThread.run(Unknown Source)
2017-sty-20 08:53:46,305 ERROR [AWT-EventQueue-0] - Caused by: java.lang.invoke.LambdaConversionException: Type mismatch for lambda argument 1: class com.goodsoft.stockbox.commons.model.c is not convertible to int
2017-sty-20 08:53:46,305 ERROR [AWT-EventQueue-0] - at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(Unknown Source)
Interesting error log is:
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch for lambda argument 1: class com.goodsoft.stockbox.commons.model.c is not convertible to int
... so maybe there is no problem with Lambdas but with masked objects using by lambda ?
Method BEFORE change to lambda looks like(works fine) :
bidAskDiffChangeObserver = new BidAskDiffChangeObserver(instrument,
new IDiffValueChangeDelegate() {
@Override
public void valueChanged(int newValue, ValueChangeType type) {
mainRangeAxis.updateSpread(newValue);
}
});
... and AFTER change to Lambda expression(do not work):
bidAskDiffChangeObserver = new BidAskDiffChangeObserver(instrument,
(newValue, type) -> mainRangeAxis.updateSpread(newValue));
It is called by:
int newValue = computeBidAskDifference();
ValueChangeType type = previousValue > newValue ? ValueChangeType.DROP :
previousValue < newValue ? ValueChangeType.GROWTH : ValueChangeType.EQUAL;
if (delegate != null)
delegate.valueChanged(newValue, type);
Which option I should use to add lambda condition ?
Without masking everything works fine (with option -dontoptimize
).
My proguard options in pom.xml now look like this:
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.10</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<injar>StockBox.jar</injar>
<outjar>StockBox.jar</outjar>
<options>
<option>-allowaccessmodification</option>
<option>-keepdirectories</option>
<option>-keep public class com.goodsoft.stockbox.Main { *; }</option>
<option>-keep public class * implements
com.goodsoft.stockbox.base.model.config.IConvertibleConfiguration
{ *;}
</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
<option>-keepattributes RuntimeVisibleAnnotations</option>
<option>-keep @javax.persistence.* class * { *;}</option>
<option>-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
</option>
<option>-keep @org.springframework.context.annotation.Configuration class *</option>
<option>-keep @org.springframework.beans.factory.annotation.Service class *</option>
<option>-keep @org.springframework.stereotype.Component class *</option>
<option>-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired *;
@org.springframework.beans.factory.annotation.Value *;
@org.springframework.context.annotation.Bean *;
}
</option>
<option>-adaptresourcefilecontents **.properties</option>
<option>-keepattributes
Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
</option>
</options>
<maxMemory>512m</maxMemory>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>${proguard.version}</version>
</dependency>
</dependencies>
</plugin>
EDIT
I tried add maven options as -optimizations !method/removal/parameter
and -optimizations !method/marking/static
but do not help.
SOLVED
There is problem with optimization changing enums to integer.
Just turn off this optimization and works fine.
<option>-optimizations !class/unboxing/enum</option>