1

I'm getting null pointer exception and have no ideas on how to overcome this issue and obfuscate the code. Do you have any ideas?

I'm working to obfuscate some libraries of a [Maven] Spring-Boot project with Proguard (proguard + proguard-maven-plugin)

Stack trace:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.wvengen:proguard-maven-plugin:2.0.11:proguard (proguard) on project XXX: Execution proguard of goal com.github.wvengen:proguard-maven-plugin:2.0.11:proguard failed.
(...)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution proguard of goal com.github.wvengen:proguard-maven-plugin:2.0.11:proguard failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
Caused by: java.lang.NullPointerException
at com.github.wvengen.maven.proguard.ProGuardMojo.execute(ProGuardMojo.java:506)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
... 20 more

POM build plugin:

<plugin>
 <groupId>com.github.wvengen</groupId>
 <artifactId>proguard-maven-plugin</artifactId>
 <version>2.0.11</version>
 <executions>
  <execution>
   <id>proguard</id>
   <phase>package</phase>
   <goals>
    <goal>proguard</goal>
   </goals>
  </execution>
 </executions>
 <configuration>
  <obfuscate>true</obfuscate>
  <injar>${project.build.finalName}.jar</injar>
  <outjar>${project.build.finalName}-small.jar</outjar>
  <outputDirectory>${project.build.directory}/proguard</outputDirectory>
  <proguardInclude>${basedir}/proguard.conf</proguardInclude>
  <libs>
   <lib>${java.bootstrap.classes}</lib>
   <lib>${java.cryptographic.extension.classes}</lib>
   <lib>${java.secure.socket.extension.classes}</lib>
  </libs>
  <injarNotExistsSkip>true</injarNotExistsSkip>
  <options>
 </options>
</configuration>
<dependencies>
 <dependency>
  <groupId>net.sf.proguard</groupId>
   <artifactId>proguard-base</artifactId>
   <version>5.2.1</version>
   <scope>runtime</scope>
  </dependency>
 </dependencies>
</plugin>
Marco
  • 11
  • 3
  • 3
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Teepeemm Jan 28 '16 at 15:49
  • @Teepeemm it is probably not a duplicate of that (famous) question since it is not code provided by the user by a plugin, the NPE is coming from a wrong configuration of the maven plugin most probably – A_Di-Matteo Jan 28 '16 at 19:23
  • @Marco Can you post your updated solution? Thank you – ALM Aug 17 '16 at 13:49

1 Answers1

1

Given the mentioned stacktrace and looking a the source code of the plugin for the 2.0.11 version, the NullPointerException is thrown in this block of the ProGuardMojo class:

502     if (libs != null) {
503         for (Iterator i = libs.iterator(); i.hasNext();) {
504             Object lib = i.next();
505             args.add("-libraryjars");
506             args.add(fileNameToString(lib.toString()));
507         }
508     }

Which means most probably the lib.toString() is an invocation of a method on a null reference.

From the plugin configuration you mentioned, we can see:

<libs>
   <lib>${java.bootstrap.classes}</lib>
   <lib>${java.cryptographic.extension.classes}</lib>
   <lib>${java.secure.socket.extension.classes}</lib>
</libs>

So, most probably one of these Maven properties is not set, passed as empty/null and causing the error.

You should check whether these properties have a valid value or were supposed to be passed from the command line and was not the case.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128