InvalidDefinitionException with ProGuard

I have a maven project that calls different jar files. I want to obfuscate only a specific code and keep all the dependencies
it fails at run time when it starts reading an excel file: Cannot construct an instance of `org.apache.spark.rdd.RDDOperationScope
Any ideas how to solve this please? thanks!

Hi Amira,

It looks like you’re (de-)serializing JSON data to an object. Is is possible the corresponding class still has obfuscated field names? If so, these should be kept as shown here:

You can prevent ProGuard from obfuscating certain dependencies by adding the following -keep option.
-keep,allowshrinking,allowoptimization class com.example.** { *; }

If ProGuard should not shrink or optimize the dependency either, please use;
-keep class com.example.** { *; }

You can verify which classes are affected by your -keep options using the ProGuard Playground

Kind regards,

Jonas

Thank you Jonas,
I add several rules for Jackson dependency, spark dependency but they didn’t work
Please note that the warning shows a class from a dependency, not my code so I don’t have access
to that code, I only want to keep everything except some packages that I have created.

I apply -keep class com.example.** { *; } for all the external jar
but the issue still exist.
Help please this is urgent & thank you

Hi @Amira ,

You can keep everything in a certain package you made yourself as follows;
-keep,includecode class !com.mypackage.processed.with.proguard.** { *; }

Please note this will disable all three features of ProGuard (shrinking, optimization & obfuscation) for all classes except the ones mentioned in the -keep rule.

Kind regards,

Jonas

Any idea how to fix the issue please
Config:
@proguard_jmods.cfg
-keep,includecode class !com.mass.massdata.** { *; }
-dontwarn **
-dontnote
-dontpreverify
-dontshrink
-dontoptimize
-keepattributes SourceFile, LineNumberTable
-renamesourcefileattribute MyApplication
-keepnames class ** implements com.mass.massdata.utils.ISerialisable
-keepclassmembers class ** implements com.mass.massdata.utils.ISerialisable {
;
}

-repackageclasses ‘’
-renamesourcefileattribute SourceFile
-keepattributes Annotation,Signature,Annotation,InnerClasses,EnclosingMethod,SourceFile,LineNumberTable
-adaptresourcefilenames

-keep class org.apache.spark.** { ; }
-keep class com.crealytics.
* { *; }
-keepdirectories org/apache/spark/ui/static
-keepdirectories org/apache/spark/sql/execution/ui/static

Error:
2021-08-26 11:31:05,233 ERROR [MASSMINER] ExcelReader:71 - com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of org.apache.spark.rdd.RDDOperationScope (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (String)"{“id”:“0”,“name”:“parallelize”}"; line: 1, column: 2]

Hi Amira,

Does your project work when you disable the obfuscation step of ProGuard using -dontobfuscate?

Since Spark is written in Scala, can you try keeping the Scala attributes as my colleague James explained in a different topic, here.

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,MethodParameters,ConstantValue,Module,ModulePackages,LocalVariableTable,LocalVariableTypeTable,Scala*

If that didn’t work either, can you please provide us with a sample that recreates the issue?

Kind regards,

Jonas

Hello,
Does your project work when you disable the obfuscation step of ProGuard using -dontobfuscate ?
Yes
I will try and get back to you
Thank you

Hello,
Thank you so much it works and the error didn’t appear after adding scala*
I still have one error related to path:
I have this 2 lines of code:
String path = MassFeedsLauncher.class.getResource("/hadoop").getPath();
System.setProperty(“hadoop.home.dir”, path);
and I have a folder called hadoop under : src/main/resources
Error:
Caused by: java.lang.NullPointerException: Cannot invoke “java.net.URL.getPath()” because the return value of “java.lang.Class.getResource(String)” is null
at com.mass.massfeedsview.exe.MassFeedsLauncher.start(SourceFile:103)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(SourceFile:846)

Thank you for your help

Hi @Amira ,

This issue is documented in our troubleshooting section under “MissingResourceException or NullPointerException”.

From the manual;

Your processed code may be unable to find some resource files. ProGuard simply copies resource files over from the input jars to the output jars. Their names and contents remain unchanged, unless you specify the options -adaptresourcefilenames and/or -adaptresourcefilecontents. Furthermore, directory entries in jar files aren’t copied, unless you specify the option -keepdirectories. Note that Sun advises against calling Class.getResource() for directories (Sun Bug #4761949](http://bugs.sun.com/view_bug.do?bug_id=4761949)).

Kind regards,

Jonas

Thank you
Any idea please about this error
java.lang.VerifyError: Expecting a stackmap frame at branch target 91
Exception Details:
Location:
javafx/application/Application.launch([Ljava/lang/String;)V @26: if_icmpge
Reason:
Expected stackmap frame at this location.
Bytecode:
0000000: b800 28b6 002a 4c03 3d01 4e2b 3a04 1904
0000010: be36 0503 3606 1506 1505 a200 4119 0415
Thank you