[ 
https://issues.apache.org/jira/browse/MNG-7449?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17518729#comment-17518729
 ] 

Tamás Cservenák commented on MNG-7449:
--------------------------------------

IMHO you are doing it wrong here: IF we talk about this class: 
https://github.com/apache/maven/blob/master/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.java#L91
 then for sure you are doing it wrong.

As you can see (lines 89, 90), this is a component, it means it is managed (and 
injected) by container, and is NOT MEANT to be instantiated manually as you do 
({{StringVisitorModelInterpolator interpolator = new 
StringVisitorModelInterpolator();}}). Your fix that will work from introduction 
of this class (Maven 3.6.2) and latest Maven version is:

Instead using {{new}} to instantiate it, inject the singleton instance like 
this (if in Mojo):

{noformat}
@Inject
private StringVisitorModelInterpolator interpolator;
{noformat}

And then use {{interpolator}} as before.

This is NOT a regression either: as user is self-instantiating a component 
instance, he does not inject fields that otherwise container would inject. This 
is plain misuse of the class. If injected as component, the code above would 
not NPE and would work from Maven 3.6.2 to latest release.

> [REGRESSION] StringVisitorModelInterpolator NullPointerException
> ----------------------------------------------------------------
>
>                 Key: MNG-7449
>                 URL: https://issues.apache.org/jira/browse/MNG-7449
>             Project: Maven
>          Issue Type: Bug
>          Components: Inheritance and Interpolation
>    Affects Versions: 3.8.5
>            Reporter: Ronnie de Lang
>            Priority: Major
>
> Since Maven 3.8.5 our own custom Maven plugin is failing with a 
> NullPointerException when trying to interpolate Maven properties in a Maven 
> model.
> Code:
> {code:java}
> StringVisitorModelInterpolator interpolator = new 
> StringVisitorModelInterpolator();
> interpolated = interpolator.interpolateModel(model, null, new 
> DefaultModelBuildingRequest(), new ModelProblemCollector() {
>     @Override
>     public void add(ModelProblemCollectorRequest 
> modelProblemCollectorRequest) {
>         problems.add(modelProblemCollectorRequest);
>     }
> }); {code}
> Stacktrace:
> {code:java}
> [ERROR] Failed to execute goal 
> nl.ing.cis.tools.deploy:deploy-configuration-maven-plugin:5.2.0:flatten 
> (default) on project DNL_PMDM_HelloYou: Execution default of goal 
> nl.ing.cis.tools.deploy:deploy-configuration-maven-plugin:5.2.0:flatten 
> failed.: NullPointerException -> [Help 1]
> org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute 
> goal nl.ing.cis.tools.deploy:deploy-configuration-maven-plugin:5.2.0:flatten 
> (default) on project DNL_PMDM_HelloYou: Execution default of goal 
> nl.ing.cis.tools.deploy:deploy-configuration-maven-plugin:5.2.0:flatten 
> failed.
>     at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute 
> (MojoExecutor.java:306)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
> (MojoExecutor.java:211)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
> (MojoExecutor.java:165)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
> (MojoExecutor.java:157)
>     at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject 
> (LifecycleModuleBuilder.java:121)
>     at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject 
> (LifecycleModuleBuilder.java:81)
>     at 
> org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build
>  (SingleThreadedBuilder.java:56)
>     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute 
> (LifecycleStarter.java:127)
>     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
>     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
>     at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
>     at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
>     at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
>     at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>     at sun.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:62)
>     at sun.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke (Method.java:498)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced 
> (Launcher.java:282)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launch 
> (Launcher.java:225)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode 
> (Launcher.java:406)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.main 
> (Launcher.java:347)
> Caused by: org.apache.maven.plugin.PluginExecutionException: Execution 
> default of goal 
> nl.ing.cis.tools.deploy:deploy-configuration-maven-plugin:5.2.0:flatten 
> failed.
>     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo 
> (DefaultBuildPluginManager.java:148)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute 
> (MojoExecutor.java:301)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
> (MojoExecutor.java:211)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
> (MojoExecutor.java:165)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
> (MojoExecutor.java:157)
>     at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject 
> (LifecycleModuleBuilder.java:121)
>     at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject 
> (LifecycleModuleBuilder.java:81)
>     at 
> org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build
>  (SingleThreadedBuilder.java:56)
>     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute 
> (LifecycleStarter.java:127)
>     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
>     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
>     at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
>     at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
>     at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
>     at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>     at sun.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:62)
>     at sun.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke (Method.java:498)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced 
> (Launcher.java:282)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launch 
> (Launcher.java:225)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode 
> (Launcher.java:406)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.main 
> (Launcher.java:347)
> Caused by: java.lang.NullPointerException
>     at 
> org.apache.maven.model.interpolation.AbstractStringBasedModelInterpolator.createValueSources
>  (AbstractStringBasedModelInterpolator.java:165)
>     at 
> org.apache.maven.model.interpolation.StringVisitorModelInterpolator.interpolateModel
>  (StringVisitorModelInterpolator.java:101)
>     at 
> nl.ing.cis.tools.tibcodeploy.utils.maven.PropertiesInterpolator.interpolateProperties
>  (PropertiesInterpolator.java:87)
>     at nl.ing.cis.tools.deploy.build.common.AbstractBuilder.replaceProperties 
> (AbstractBuilder.java:236)
>     at 
> nl.ing.cis.tools.deploy.build.common.AbstractBuilder.replacePropertiesInXml 
> (AbstractBuilder.java:261)
>     at 
> nl.ing.cis.tools.deploy.build.flattenedbindings.FlattenedBindingsBuilder.prefetchDtlScmResources
>  (FlattenedBindingsBuilder.java:683)
>     at 
> nl.ing.cis.tools.deploy.build.flattenedbindings.FlattenedBindingsBuilder.build
>  (FlattenedBindingsBuilder.java:91)
>     at nl.ing.cis.tools.deploy.configuration.maven.FlattenMojo.buildBindings 
> (FlattenMojo.java:140)
>     at nl.ing.cis.tools.deploy.configuration.maven.FlattenMojo.doFlatten 
> (FlattenMojo.java:122)
>     at nl.ing.cis.tools.deploy.configuration.maven.FlattenMojo.execute 
> (FlattenMojo.java:101)
>     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo 
> (DefaultBuildPluginManager.java:137)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute 
> (MojoExecutor.java:301)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
> (MojoExecutor.java:211)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
> (MojoExecutor.java:165)
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute 
> (MojoExecutor.java:157)
>     at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject 
> (LifecycleModuleBuilder.java:121)
>     at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject 
> (LifecycleModuleBuilder.java:81)
>     at 
> org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build
>  (SingleThreadedBuilder.java:56)
>     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute 
> (LifecycleStarter.java:127)
>     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
>     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
>     at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
>     at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
>     at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
>     at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>     at sun.reflect.NativeMethodAccessorImpl.invoke 
> (NativeMethodAccessorImpl.java:62)
>     at sun.reflect.DelegatingMethodAccessorImpl.invoke 
> (DelegatingMethodAccessorImpl.java:43)
>     at java.lang.reflect.Method.invoke (Method.java:498)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced 
> (Launcher.java:282)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launch 
> (Launcher.java:225)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode 
> (Launcher.java:406)
>     at org.codehaus.plexus.classworlds.launcher.Launcher.main 
> (Launcher.java:347) {code}
> When analysing the issue it showed that the NullPointerException is caused 
> because the AbstractStringBasedModelInterpolator tries to use the newly 
> introduced ModelVersionProcessor, but the member is null.
> Programmatically providing the interpolator with an instance of the default 
> ModelVersionProcessor class solves this issue. But that is not backwards 
> compatible as this class is new in Maven 3.8.5.
> {code:java}
> interpolator.setVersionPropertiesProcessor(new 
> DefaultModelVersionProcessor()); {code}
> Is this a bug, or am I doing something wrong here?



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to