While compiling an opensource project, I encounter a problem with a Maven
plugin that fails.
And I would like to open an issue about its problem. To be helpful to those who will search to solve it, I would like to explain how it might happen.
Execution default of goal pl.project13.maven:git-commit-id-plugin:4.0.3:revision failed. (pl.project13.maven:git-commit-id-plugin:4.0.3:revision:default:initialize)
org.apache.maven.plugin.PluginExecutionException: Execution default of goal pl.project13.maven:git-commit-id-plugin:4.0.3:revision failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:148)
at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:332)
at org.eclipse.m2e.core.internal.embedder.MavenImpl.lambda$8(MavenImpl.java:1380)
at [...]
Caused by: java.lang.NullPointerException
at pl.project13.maven.git.GitCommitIdMojo.execute(GitCommitIdMojo.java:441)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
... 30 more
For that, I've red the involved line that causes the NullPointerException
on its Git repository.
The content of the line 441 of GitCommitIdMojo.java
is :
List<MavenProject> sortedProjects =
Optional.ofNullable(session.getProjectDependencyGraph())
.map(graph -> graph.getSortedProjects())
.orElseGet(() -> {
log.warn("Maven's dependency graph is null. Assuming project is the only one executed.");
return Collections.singletonList(session.getCurrentProject());
});
But I'm not so experienced with Optional and other inline functions. And I wonder from where the NullPointerException
is really coming. I have no way to test it in Live, so I can only guess.
I've checked on the source file : session
is a required attribute. It shouldn't be null.
I believe that the Optional.ofNullable(...)
protects the content inside parenthesis and that the NullPointerException
isn't coming from here.
But when entering the .orElseGet(...)
part of the expression, it might fail on Collections.singletonList(session.getCurrentProject())
where session.getCurrentProject()
would return null.
Am I right?
What other parts of this statement could lead to a NullPointerException
under what conditions?
question from:
https://stackoverflow.com/questions/65926853/a-maven-plugin-fails-and-to-open-an-issue-i-would-like-to-explain-inside-how-th 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…