NullPointer with Formatter
Closed this issue · 4 comments
Describe the bug
A clear and concise description of what the bug is.
Versions (OS, Maven, Java, and others, as appropriate):
- Affected version(s) of this project: 2.18.0
- OS: WIndows 10 and Ubuntu 20.04
To Reproduce
Steps to reproduce the behavior (or a link to an example repository that reproduces the problem):
- add in pluginManagement
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>2.18.0</version>
<configuration>
<encoding>UTF-8</encoding>
<lineEnding>LF</lineEnding>
<removeTrailingWhitespace>true</removeTrailingWhitespace>
<!-- <skipJavaFormatting>true</skipJavaFormatting> -->
<configFile>${project.basedir}/src/main/config/eclipse-java-formatter.xml</configFile>
</configuration>
<executions>
<execution>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>
XML is attached eclipse-java-formatter.xml.txt
-
run
mvn formatter:format
Expected behavior
Get a formatted code
** Exception **
[ERROR] Failed to execute goal net.revelc.code.formatter:formatter-maven-plugin:2.18.0:format (default-cli) on project my-something: Execution default-cli of goal net.revelc.code.formatter:formatter-maven-plugin:2.18.0:format failed. NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal net.revelc.code.formatter:formatter-maven-plugin:2.18.0:format (default-cli) on project my-something: Execution default-cli of goal net.revelc.code.formatter:formatter-maven-plugin:2.18.0:format failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal net.revelc.code.formatter:formatter-maven-plugin:2.18.0:format failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.lang.NullPointerException
at org.eclipse.jdt.core.ToolFactory.createCodeFormatter(ToolFactory.java:190)
at net.revelc.code.formatter.java.JavaFormatter.init(JavaFormatter.java:51)
at net.revelc.code.formatter.FormatterMojo.createCodeFormatter(FormatterMojo.java:810)
at net.revelc.code.formatter.FormatterMojo.execute(FormatterMojo.java:422)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Context:
If I narrowed the issue down the Nullpointer comes from here:
String formatterId = (String) options.get(JavaCore.JAVA_FORMATTER);
if (formatterId != null) {
**IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(JavaCore.PLUGIN_ID,
JavaCore.JAVA_FORMATTER_EXTENSION_POINT_ID);**
So afaik Platform.getExtensionRegistry() is probably null, but now clue why...
The problem seems to be your config file. It has an extra line that says:
<setting id="org.eclipse.jdt.core.javaFormatter" value="org.eclipse.jdt.core.defaultJavaFormatter"/>
When I export my config from Eclipse, I don't see that field anywhere, so I'm not sure how it got into your config file. When I remove it, your config file works fine.
Doesn't look like a bug with a valid config file. Information provided.
it is a exported config file (no manual addition to file), however this change fixes the issue
it is a exported config file (no manual addition to file), however this change fixes the issue
When I exported it, that line did not exist. However, you may be using a different version of Eclipse... or you may have attempted to export all of the formatter configs into a single file, rather than exporting a single one. To export a single config, click the Edit button, and not the "Export All" button: