NullPointerException: ProGuard, Spring Boot

余生颓废 提交于 2019-12-11 13:02:50

问题


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>

回答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.



来源:https://stackoverflow.com/questions/35065609/nullpointerexception-proguard-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!