simonetallevi / maven-replacer-plugin

Automatically exported from code.google.com/p/maven-replacer-plugin
MIT License
0 stars 0 forks source link

NullPointerException when <file> is not used and <ignoreMissingFile> is "true" #40

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Trying to do replacements in multiple files (either through 
<includes:include> or <filesToInclude>) without providing a <file> parameter 
and with <ignoreMissingFile> set to "true", plugin config:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>maven-replacer-plugin</artifactId>
    <version>1.3.4</version>
    <executions>
        <execution>
            <phase>process-test-classes</phase>
            <goals>
                <goal>replace</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <includes>
            <include>target/${project.build.finalName}/META-INF/context.xml</include>
            <include>target/${project.build.finalName}/WEB-INF/classes/porting_manager.properties</include>
        </includes>
        <ignoreMissingFile>true</ignoreMissingFile>
        <replacements>
            <replacement>
                <token>$DBHOST$</token>
                <value>localhost:5432</value>
            </replacement>
            <replacement>
                <token>$DBNAME$</token>
                <value>PortaManagerWS</value>
            </replacement>
        </replacements>
        <regex>false</regex>
    </configuration>
</plugin>

2. On building, the plugin runs into a NullPointerException:

java.lang.NullPointerException
at java.io.File.<init>(File.java:222)
at 
com.google.code.maven_replacer_plugin.file.FileUtils.fileNotExists(FileUtils.jav
a:8)
at 
com.google.code.maven_replacer_plugin.ReplacerMojo.execute(ReplacerMojo.java:191
)
at 
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.ja
va:490)
at 
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycl
eExecutor.java:694)
at 
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(Def
aultLifecycleExecutor.java:556)
at 
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycle
Executor.java:535)
at 
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures
(DefaultLifecycleExecutor.java:387)
at 
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultL
ifecycleExecutor.java:348)
at 
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExec
utor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

What is the expected output? What do you see instead?
The Tokens should be replaced in both files. A NullPointerException is thrown 
instead and the build fails.

What version of the product are you using? On what operating system?
1.3.4 on linux

Please provide any additional information below.
The problem is the check for missing files on line 211 of ReplacerMojo.java. 
"file" is not checked for null values before calling 
"fileUtils.fileNotExists(file)" which therefore runs into a 
NullPointerException.

To fix this, one could either check all destinations for missing ones or simply 
check "file" for null values:
if (ignoreMissingFile && (file != null) && fileUtils.fileNotExists(file)) {
    getLog().info("Ignoring missing file");
    return;
}

Original issue reported on code.google.com by julianha...@gmail.com on 23 Nov 2010 at 4:28

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. I am working on a fix at the moment.
You don't have to set ignoreMissingFile when using multiple files (through the 
filesToInclude or includes) parameters - ignoreMissingFile is enabled by 
default in these cases.

Original comment by baker.st...@gmail.com on 24 Nov 2010 at 5:55

GoogleCodeExporter commented 9 years ago
Is this an urgent issue for you?
If not, can this wait until there are a few more fixes/enhancements done?

Original comment by baker.st...@gmail.com on 25 Nov 2010 at 10:25

GoogleCodeExporter commented 9 years ago
As you mentioned, replacements in multiple files do work if you don't set the 
ignoreMissingFiles parameter. Therefore, we can work with the current version 
and won't need the fix that urgently after all.

But thank you for the quick response nonetheless :-)

Original comment by julianha...@gmail.com on 26 Nov 2010 at 8:13

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Fixed in version 1.3.5. 
Now will simply show an error saying that the user cannot use ignoreMissingFile 
without using the file parameter. Otherwise would have needed different 
defaults for ignoreMissingFile depending on whether file (false) or includes 
(true) were used.

Original comment by baker.st...@gmail.com on 27 Nov 2010 at 5:35

GoogleCodeExporter commented 9 years ago
Just issue clean up.

Original comment by baker.st...@gmail.com on 17 Sep 2012 at 12:42