[maven] branch MNG-6819-2 created (now 5c77cc5)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[maven] branch MNG-6819-2 created (now 5c77cc5)

slachiewicz
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a change to branch MNG-6819-2
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at 5c77cc5  [MNG-6819] Fix also NPE in StringSearchModelInterpolator

This branch includes the following new commits:

     new fa20fb4  [MNG-6819] Fix NullPointerException in StringVisitorModelInterpolator
     new 29a054c  [MNG-6819] Refactor unit tests for ModelInterpolator
     new 5c77cc5  [MNG-6819] Fix also NPE in StringSearchModelInterpolator

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Reply | Threaded
Open this post in threaded view
|

[maven] 01/03: [MNG-6819] Fix NullPointerException in StringVisitorModelInterpolator

slachiewicz
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MNG-6819-2
in repository https://gitbox.apache.org/repos/asf/maven.git

commit fa20fb478d648090a7aa9f9d000d0753acf073e6
Author: 碎镜 <[hidden email]>
AuthorDate: Fri Dec 13 20:07:20 2019 +0800

    [MNG-6819] Fix NullPointerException in StringVisitorModelInterpolator
   
    Closes #301
---
 .../maven/model/interpolation/StringVisitorModelInterpolator.java       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.java
index 98e36f6..313c4f7 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.java
@@ -1420,7 +1420,7 @@ public class StringVisitorModelInterpolator
                     {
                         String value = (String) v;
                         String inter = interpolate( value );
-                        if ( value != inter )
+                        if ( value != inter && inter != null )
                         {
                             entry.setValue( inter );
                         }

Reply | Threaded
Open this post in threaded view
|

[maven] 02/03: [MNG-6819] Refactor unit tests for ModelInterpolator

slachiewicz
In reply to this post by slachiewicz
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MNG-6819-2
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 29a054c7d5015607d301717093beca7e49df1842
Author: Sylwester Lachiewicz <[hidden email]>
AuthorDate: Sat May 23 01:18:03 2020 +0200

    [MNG-6819] Refactor unit tests for ModelInterpolator
---
 .../AbstractModelInterpolatorTest.java             | 202 +++++++++++----------
 .../StringSearchModelInterpolatorTest.java         |  37 ++--
 .../StringVisitorModelInterpolatorTest.java        |  35 ++++
 3 files changed, 168 insertions(+), 106 deletions(-)

diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java
index 19a28c1..5cd39ca 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java
@@ -32,6 +32,9 @@ import org.apache.maven.model.building.SimpleProblemCollector;
 import org.apache.maven.model.path.PathTranslator;
 
 import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
 
 import java.io.File;
 import java.text.SimpleDateFormat;
@@ -42,19 +45,19 @@ import java.util.List;
 import java.util.Properties;
 import java.util.TimeZone;
 
+import static org.junit.Assert.*;
+
 /**
  * @author jdcasey
  */
 public abstract class AbstractModelInterpolatorTest
-    extends TestCase
 {
+    protected ModelInterpolator interpolator;
     private Properties context;
 
-    protected void setUp()
-        throws Exception
+    @Before
+    public void setUp()
     {
-        super.setUp();
-
         context = new Properties();
         context.put( "basedir", "myBasedir" );
         context.put( "project.baseUri", "myBaseUri" );
@@ -68,24 +71,13 @@ public abstract class AbstractModelInterpolatorTest
         assertEquals( "Expected no fatals", 0, collector.getFatals().size() );
     }
 
-    /**
-     * @deprecated instead use {@link #assertCollectorState(int, int, int, SimpleProblemCollector)}
-     */
-    @Deprecated
-    protected void assertColllectorState( int numFatals, int numErrors, int numWarnings,
-                                          SimpleProblemCollector collector )
+    protected void assertCollectorState( int numFatals, int numErrors, int numWarnings, SimpleProblemCollector collector )
     {
-        assertEquals( "Errors",  numErrors, collector.getErrors().size() );
+        assertEquals( "Errors", numErrors, collector.getErrors().size() );
         assertEquals( "Warnings", numWarnings, collector.getWarnings().size() );
         assertEquals( "Fatals", numFatals, collector.getFatals().size() );
     }
 
-    protected void assertCollectorState( int numFatals, int numErrors, int numWarnings,
-                                          SimpleProblemCollector collector )
-    {
-        assertColllectorState(numFatals, numErrors, numWarnings, collector);
-    }
-
     private ModelBuildingRequest createModelBuildingRequest( Properties p )
     {
         ModelBuildingRequest config = new DefaultModelBuildingRequest();
@@ -96,6 +88,7 @@ public abstract class AbstractModelInterpolatorTest
         return config;
     }
 
+    @Test
     public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat()
     {
         Calendar cal = Calendar.getInstance();
@@ -121,13 +114,13 @@ public abstract class AbstractModelInterpolatorTest
 
         Date secondTestDate = cal.getTime();
 
-        SimpleDateFormat format =
-            new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
+        SimpleDateFormat format = new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
         format.setTimeZone( MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE );
         assertEquals( "1976-11-11T00:16:00Z", format.format( firstTestDate ) );
         assertEquals( "1976-11-11T23:16:00Z", format.format( secondTestDate ) );
     }
 
+    @Test
     public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover()
     {
         Calendar cal = Calendar.getInstance();
@@ -146,15 +139,14 @@ public abstract class AbstractModelInterpolatorTest
 
         Date secondTestDate = cal.getTime();
 
-        SimpleDateFormat format =
-            new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
+        SimpleDateFormat format = new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT );
         format.setTimeZone( MavenBuildTimestamp.DEFAULT_BUILD_TIME_ZONE );
         assertEquals( "2014-06-15T23:16:00Z", format.format( firstTestDate ) );
         assertEquals( "2014-11-16T00:16:00Z", format.format( secondTestDate ) );
     }
 
-    public void testShouldNotThrowExceptionOnReferenceToNonExistentValue()
-        throws Exception
+    @Test
+    public void testShouldNotThrowExceptionOnReferenceToNonExistentValue() throws Exception
     {
         Model model = new Model();
 
@@ -166,15 +158,15 @@ public abstract class AbstractModelInterpolatorTest
         ModelInterpolator interpolator = createInterpolator();
 
         final SimpleProblemCollector collector = new SimpleProblemCollector();
-        Model out =
-            interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
+        Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
+                collector );
 
-        assertProblemFree(  collector );
+        assertProblemFree( collector );
         assertEquals( "${test}/somepath", out.getScm().getConnection() );
     }
 
-    public void testShouldThrowExceptionOnRecursiveScmConnectionReference()
-        throws Exception
+    @Test
+    public void testShouldThrowExceptionOnRecursiveScmConnectionReference() throws Exception
     {
         Model model = new Model();
 
@@ -183,22 +175,15 @@ public abstract class AbstractModelInterpolatorTest
 
         model.setScm( scm );
 
-        try
-        {
-            ModelInterpolator interpolator = createInterpolator();
-
-            final SimpleProblemCollector collector = new SimpleProblemCollector();
-            interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector );
-            assertCollectorState(  0, 1, 0, collector );
-        }
-        catch ( Exception e )
-        {
+        ModelInterpolator interpolator = createInterpolator();
 
-        }
+        final SimpleProblemCollector collector = new SimpleProblemCollector();
+        interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector );
+        assertCollectorState(  0, 1, 0, collector );
     }
 
-    public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpression()
-        throws Exception
+    @Test
+    public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpression() throws Exception
     {
         Model model = new Model();
 
@@ -212,16 +197,16 @@ public abstract class AbstractModelInterpolatorTest
         ModelInterpolator interpolator = createInterpolator();
 
         final SimpleProblemCollector collector = new SimpleProblemCollector();
-        Model out =
-            interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
+        Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
+                collector );
 
-        assertProblemFree(  collector );
+        assertProblemFree( collector );
 
         assertEquals( "test/somepath", out.getScm().getConnection() );
     }
 
-    public void testShouldInterpolateOrganizationNameCorrectly()
-        throws Exception
+    @Test
+    public void shouldInterpolateOrganizationNameCorrectly() throws Exception
     {
         String orgName = "MyCo";
 
@@ -235,15 +220,14 @@ public abstract class AbstractModelInterpolatorTest
 
         ModelInterpolator interpolator = createInterpolator();
 
-        Model out =
-            interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
-                                           new SimpleProblemCollector() );
+        Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
+                new SimpleProblemCollector() );
 
         assertEquals( orgName + " Tools", out.getName() );
     }
 
-    public void testShouldInterpolateDependencyVersionToSetSameAsProjectVersion()
-        throws Exception
+    @Test
+    public void shouldInterpolateDependencyVersionToSetSameAsProjectVersion() throws Exception
     {
         Model model = new Model();
         model.setVersion( "3.8.1" );
@@ -256,15 +240,15 @@ public abstract class AbstractModelInterpolatorTest
         ModelInterpolator interpolator = createInterpolator();
 
         final SimpleProblemCollector collector = new SimpleProblemCollector();
-        Model out =
-            interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
-        assertCollectorState(0, 0, 1, collector );
+        Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
+                collector );
+        assertCollectorState( 0, 0, 1, collector );
 
         assertEquals( "3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() );
     }
 
-    public void testShouldNotInterpolateDependencyVersionWithInvalidReference()
-        throws Exception
+    @Test
+    public void testShouldNotInterpolateDependencyVersionWithInvalidReference() throws Exception
     {
         Model model = new Model();
         model.setVersion( "3.8.1" );
@@ -292,15 +276,15 @@ public abstract class AbstractModelInterpolatorTest
         ModelInterpolator interpolator = createInterpolator();
 
         final SimpleProblemCollector collector = new SimpleProblemCollector();
-        Model out =
-            interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
+        Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
+                collector );
         assertProblemFree( collector );
 
         assertEquals( "${something}", ( out.getDependencies().get( 0 ) ).getVersion() );
     }
 
-    public void testTwoReferences()
-        throws Exception
+    @Test
+    public void testTwoReferences() throws Exception
     {
         Model model = new Model();
         model.setVersion( "3.8.1" );
@@ -314,15 +298,15 @@ public abstract class AbstractModelInterpolatorTest
         ModelInterpolator interpolator = createInterpolator();
 
         final SimpleProblemCollector collector = new SimpleProblemCollector();
-        Model out =
-            interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
+        Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
+                collector );
         assertCollectorState( 0, 0, 2, collector );
 
         assertEquals( "foo-3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() );
     }
 
-    public void testBasedir()
-        throws Exception
+    @Test
+    public void testBasedir() throws Exception
     {
         Model model = new Model();
         model.setVersion( "3.8.1" );
@@ -343,8 +327,8 @@ public abstract class AbstractModelInterpolatorTest
         assertEquals( "file://localhost/myBasedir/temp-repo", ( out.getRepositories().get( 0 ) ).getUrl() );
     }
 
-    public void testBaseUri()
-        throws Exception
+    @Test
+    public void testBaseUri() throws Exception
     {
         Model model = new Model();
         model.setVersion( "3.8.1" );
@@ -365,10 +349,10 @@ public abstract class AbstractModelInterpolatorTest
         assertEquals( "myBaseUri/temp-repo", ( out.getRepositories().get( 0 ) ).getUrl() );
     }
 
-    public void testEnvars()
-        throws Exception
+    @Test
+    public void testEnvars() throws Exception
     {
-         Properties context = new Properties();
+        Properties context = new Properties();
 
         context.put( "env.HOME", "/path/to/home" );
 
@@ -383,15 +367,15 @@ public abstract class AbstractModelInterpolatorTest
         ModelInterpolator interpolator = createInterpolator();
 
         final SimpleProblemCollector collector = new SimpleProblemCollector();
-        Model out =
-            interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
+        Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
+                collector );
         assertProblemFree( collector );
 
         assertEquals( "/path/to/home", out.getProperties().getProperty( "outputDirectory" ) );
     }
 
-    public void testEnvarExpressionThatEvaluatesToNullReturnsTheLiteralString()
-        throws Exception
+    @Test
+    public void envarExpressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception
     {
         Model model = new Model();
 
@@ -404,15 +388,15 @@ public abstract class AbstractModelInterpolatorTest
         ModelInterpolator interpolator = createInterpolator();
 
         final SimpleProblemCollector collector = new SimpleProblemCollector();
-        Model out =
-            interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
+        Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
+                collector );
         assertProblemFree( collector );
 
         assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${env.DOES_NOT_EXIST}" );
     }
 
-    public void testExpressionThatEvaluatesToNullReturnsTheLiteralString()
-        throws Exception
+    @Test
+    public void expressionThatEvaluatesToNullReturnsTheLiteralString() throws Exception
     {
         Model model = new Model();
 
@@ -425,15 +409,15 @@ public abstract class AbstractModelInterpolatorTest
         ModelInterpolator interpolator = createInterpolator();
 
         final SimpleProblemCollector collector = new SimpleProblemCollector();
-        Model out =
-            interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector );
+        Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
+                collector );
         assertProblemFree( collector );
 
         assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${DOES_NOT_EXIST}" );
     }
 
-    public void testShouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly()
-        throws Exception
+    @Test
+    public void shouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly() throws Exception
     {
         Model model = new Model();
 
@@ -472,8 +456,8 @@ public abstract class AbstractModelInterpolatorTest
         assertEquals( build.getSourceDirectory(), resIt.next().getDirectory() );
     }
 
-    public void testShouldInterpolateUnprefixedBasedirExpression()
-        throws Exception
+    @Test
+    public void shouldInterpolateUnprefixedBasedirExpression() throws Exception
     {
         File basedir = new File( "/test/path" );
         Model model = new Model();
@@ -485,21 +469,57 @@ public abstract class AbstractModelInterpolatorTest
         ModelInterpolator interpolator = createInterpolator();
 
         final SimpleProblemCollector collector = new SimpleProblemCollector();
-        Model result = interpolator.interpolateModel( model, basedir, createModelBuildingRequest( context ), collector );
-        assertProblemFree(  collector );
+        Model result = interpolator.interpolateModel( model, basedir, createModelBuildingRequest( context ),
+                collector );
+        assertProblemFree( collector );
 
 
         List<Dependency> rDeps = result.getDependencies();
         assertNotNull( rDeps );
         assertEquals( 1, rDeps.size() );
         assertEquals( new File( basedir, "artifact.jar" ).getAbsolutePath(),
-                      new File( rDeps.get( 0 ).getSystemPath() ).getAbsolutePath() );
+                new File( rDeps.get( 0 ).getSystemPath() ).getAbsolutePath() );
     }
 
-    protected abstract ModelInterpolator createInterpolator( PathTranslator translator )
-        throws Exception;
+    @Test
+    public void testRecursiveExpressionCycleNPE() throws Exception
+    {
+        Properties props = new Properties();
+        props.setProperty( "aa", "${bb}" );
+        props.setProperty( "bb", "${aa}" );
+        DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
+
+        Model model = new Model();
+        model.setProperties( props );
+
+        SimpleProblemCollector collector = new SimpleProblemCollector();
+        ModelInterpolator interpolator = createInterpolator();
+        interpolator.interpolateModel( model, null, request, collector );
+
+        assertCollectorState( 0, 2, 0, collector );
+        assertTrue( collector.getErrors().get( 0 ).contains( "Detected the following recursive expression cycle" ) );
+    }
+
+    @Test
+    public void testRecursiveExpressionCycleBaseDir() throws Exception
+    {
+        Properties props = new Properties();
+        props.setProperty( "basedir", "${basedir}" );
+        DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
+
+        Model model = new Model();
+        model.setProperties( props );
+
+        SimpleProblemCollector collector = new SimpleProblemCollector();
+        ModelInterpolator interpolator = createInterpolator();
+        interpolator.interpolateModel( model, null, request, collector );
+
+        assertCollectorState( 0, 1, 0, collector );
+        assertEquals(
+                "Resolving expression: '${basedir}': Detected the following recursive expression cycle in 'basedir': [basedir]",
+                collector.getErrors().get( 0 ) );
+    }
 
-    protected abstract ModelInterpolator createInterpolator()
-        throws Exception;
+    protected abstract ModelInterpolator createInterpolator() throws Exception;
 
 }
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java
index 479f681..3672c20 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java
@@ -25,6 +25,7 @@ import org.apache.maven.model.Model;
 import org.apache.maven.model.building.DefaultModelBuildingRequest;
 import org.apache.maven.model.building.ModelBuildingRequest;
 import org.apache.maven.model.building.SimpleProblemCollector;
+import org.junit.Test;
 
 import java.io.File;
 import java.lang.reflect.Field;
@@ -37,6 +38,8 @@ import java.util.concurrent.FutureTask;
 import static org.hamcrest.CoreMatchers.anyOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 /**
  * StringSearchModelInterpolatorTest - not in use
@@ -48,28 +51,19 @@ import static org.hamcrest.MatcherAssert.assertThat;
 public class StringSearchModelInterpolatorTest
     extends AbstractModelInterpolatorTest
 {
-
-    protected ModelInterpolator interpolator;
-
     @Override
-    protected void setUp()
-        throws Exception
+    public void setUp()
     {
         super.setUp();
         interpolator = new StringSearchModelInterpolator();
     }
 
-
-    protected ModelInterpolator createInterpolator( org.apache.maven.model.path.PathTranslator translator )
-    {
-        return this.interpolator;
-    }
-
     protected ModelInterpolator createInterpolator()
     {
         return this.interpolator;
     }
 
+    @Test
     public void testInterpolateStringArray()
     {
         Model model = new Model();
@@ -99,6 +93,7 @@ public class StringSearchModelInterpolatorTest
         return config;
     }
 
+    @Test
     public void testInterpolateObjectWithStringArrayField()
     {
         Model model = new Model();
@@ -123,6 +118,7 @@ public class StringSearchModelInterpolatorTest
         assertEquals( "value2", obj.values[1] );
     }
 
+    @Test
     public void testInterpolateObjectWithStringListField()
     {
         Model model = new Model();
@@ -149,6 +145,7 @@ public class StringSearchModelInterpolatorTest
         assertEquals( "value2", obj.values.get( 1 ) );
     }
 
+    @Test
     public void testInterpolateObjectWithStringListFieldAndOneLiteralValue()
     {
         Model model = new Model();
@@ -175,6 +172,7 @@ public class StringSearchModelInterpolatorTest
         assertEquals( "value2", obj.values.get( 1 ) );
     }
 
+    @Test
     public void testInterpolateObjectWithUnmodifiableStringListField()
     {
         Model model = new Model();
@@ -198,6 +196,7 @@ public class StringSearchModelInterpolatorTest
         assertEquals( "${key}", obj.values.get( 0 ) );
     }
 
+    @Test
     public void testInterpolateObjectWithStringArrayListField()
     {
         Model model = new Model();
@@ -228,6 +227,7 @@ public class StringSearchModelInterpolatorTest
         assertEquals( "value4", ( (String[]) obj.values.get( 1 ) )[1] );
     }
 
+    @Test
     public void testInterpolateObjectWithStringToStringMapField()
     {
         Model model = new Model();
@@ -254,6 +254,7 @@ public class StringSearchModelInterpolatorTest
         assertEquals( "value2", obj.values.get( "key2" ) );
     }
 
+    @Test
     public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue()
     {
         Model model = new Model();
@@ -280,6 +281,7 @@ public class StringSearchModelInterpolatorTest
         assertEquals( "value2", obj.values.get( "key2" ) );
     }
 
+    @Test
     public void testInterpolateObjectWithUnmodifiableStringToStringMapField()
     {
         Model model = new Model();
@@ -303,6 +305,7 @@ public class StringSearchModelInterpolatorTest
         assertEquals( "${key}", obj.values.get( "key" ) );
     }
 
+    @Test
     public void testInterpolateObjectWithStringToStringArrayMapField()
     {
         Model model = new Model();
@@ -333,6 +336,7 @@ public class StringSearchModelInterpolatorTest
         assertEquals( "value4", ( (String[]) obj.values.get( "key2" ) )[1] );
     }
 
+    @Test
     public void testInterpolateObjectWithPomFile()
             throws Exception
     {
@@ -364,6 +368,7 @@ public class StringSearchModelInterpolatorTest
         ) ) );
     }
 
+    @Test
     public void testNotInterpolateObjectWithFile()
             throws Exception
     {
@@ -411,6 +416,7 @@ public class StringSearchModelInterpolatorTest
         return (Map<Class<?>, ?>) field.get( null );
     }
 
+    @Test
     public void testNotInterpolateFile()
             throws Exception
     {
@@ -438,6 +444,7 @@ public class StringSearchModelInterpolatorTest
     }
 
 
+    @Test
     public void testConcurrentInterpolation()
         throws Exception
     {
@@ -452,7 +459,6 @@ public class StringSearchModelInterpolatorTest
 
         final StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator();
 
-
         int numItems = 100;
         final CountDownLatch countDownLatch = new CountDownLatch(1);
 
@@ -497,7 +503,6 @@ public class StringSearchModelInterpolatorTest
         return new ObjectWithMixedProtection( values, values2, values3, "${key5}" );
     }
 
-
     private static final class ObjectWithStringArrayField
     {
         private final String[] values;
@@ -567,6 +572,7 @@ public class StringSearchModelInterpolatorTest
         }
     }
 
+    @Test
     public void testFinalFieldsExcludedFromInterpolation()
     {
         Properties props = new Properties();
@@ -578,7 +584,7 @@ public class StringSearchModelInterpolatorTest
         StringSearchModelInterpolator interpolator = new StringSearchModelInterpolator();
         interpolator.interpolateObject( new ClassWithFinalField(), new Model(), null, request, problems );
 
-        assertProblemFree(  problems );
+        assertProblemFree( problems );
     }
 
     static class ClassWithFinalField
@@ -586,7 +592,8 @@ public class StringSearchModelInterpolatorTest
         public static final String CONSTANT = "${expression}";
     }
 
-    public void testLocationTrackerShouldBeExcludedFromInterpolation()
+    @Test
+    public void locationTrackerShouldBeExcludedFromInterpolation()
     {
         Properties props = new Properties();
         props.setProperty( "expression", "value" );
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java
new file mode 100644
index 0000000..bd201ed
--- /dev/null
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java
@@ -0,0 +1,35 @@
+package org.apache.maven.model.interpolation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public class StringVisitorModelInterpolatorTest extends AbstractModelInterpolatorTest
+{
+    @Override
+    public void setUp()
+    {
+        super.setUp();
+        interpolator = new StringVisitorModelInterpolator();
+    }
+
+    protected ModelInterpolator createInterpolator()
+    {
+        return this.interpolator;
+    }
+}
\ No newline at end of file

Reply | Threaded
Open this post in threaded view
|

[maven] 03/03: [MNG-6819] Fix also NPE in StringSearchModelInterpolator

slachiewicz
In reply to this post by slachiewicz
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch MNG-6819-2
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 5c77cc55c210a582e445931a1c2a739104778f39
Author: Sylwester Lachiewicz <[hidden email]>
AuthorDate: Sat May 23 01:30:47 2020 +0200

    [MNG-6819] Fix also NPE in StringSearchModelInterpolator
---
 .../maven/model/interpolation/StringSearchModelInterpolator.java      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java
index af4d105..93e53b7 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java
@@ -365,7 +365,7 @@ public class StringSearchModelInterpolator
 
                 String interpolated = ctx.interpolate( value );
 
-                if ( !interpolated.equals( value ) )
+                if ( interpolated != null && !interpolated.equals( value ) )
                 {
                     field.set( target, interpolated );
                 }
@@ -459,7 +459,7 @@ public class StringSearchModelInterpolator
                     {
                         String interpolated = ctx.interpolate( (String) value );
 
-                        if ( !interpolated.equals( value ) )
+                        if ( interpolated != null && !interpolated.equals( value ) )
                         {
                             try
                             {