Skip to content

Maven plugin, empty global variable value provided in POM throws NPE #47

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Lilianne-Blaze opened this issue Dec 30, 2023 · 5 comments
Closed
Assignees
Labels

Comments

@Lilianne-Blaze
Copy link

Could you please add an option to ignore (treat as empty string?) variables that are set to empty or undeclared properties?

Here's an example:

I have plugin

                <groupId>io.github.git-commit-id</groupId>
                <artifactId>git-commit-id-maven-plugin</artifactId>
                <version>7.0.0</version>

Which sets properties including "${git.build.time}"

I have your plugin with

                    <vars>
                        <GIT_BUILD_TIME>${git.build.time}</GIT_BUILD_TIME>

Which is then used in the source like that

log.info("Build time: /*$GIT_BUILD_TIME$*/");

Everything works as intended

Now try to change it to

                        <GIT_BUILD_TIME></GIT_BUILD_TIME>

or

                        <GIT_BUILD_TIME>${git.build.timeUNDECLARED}</GIT_BUILD_TIME>

Both result in error:

Failed to execute goal com.igormaznitsa:jcp:7.1.0:preprocess (preprocess-sources) on project lbnet-maven-plugins-launch4j-wrp: Parameter is null -> [Help 1]

I tried < unknownVarAsFalse > true < /unknownVarAsFalse > but apparently it doesn't affect var declarations in pom, only var usage in sources.

Could you please add an option to handle that? " < allowEmptyVarDeclarations > " or something, to have them resolve to empty strings "" instead of throwing an error at buildtime?

p.s. Have I mentioned I really appreciate your work? I never understood why Java devs decided preprocessing is unnecessary.

@raydac
Copy link
Owner

raydac commented Dec 31, 2023

map with global vars contains null as variable value for empty string so it is bug that the preprocessor gets NPE, I will fix and just will not be adding the variable (with log) and unknownVarAsFalse will be working

@raydac raydac self-assigned this Dec 31, 2023
@raydac raydac added the bug label Dec 31, 2023
@raydac raydac changed the title Allow empty or undeclared properties in variable declarations in pom Maven plugin, empty global variable value proveded in POM generates NPE Dec 31, 2023
@raydac
Copy link
Owner

raydac commented Dec 31, 2023

I have made fix for NPE so that now it should ignore such empty variable (with log message) and flag unknownVarAsFalse will be working, you can try snapshot version

@raydac raydac changed the title Maven plugin, empty global variable value proveded in POM generates NPE Maven plugin, empty global variable value provided in POM generates NPE Dec 31, 2023
@raydac raydac changed the title Maven plugin, empty global variable value provided in POM generates NPE Maven plugin, empty global variable value provided in POM throws NPE Dec 31, 2023
@Lilianne-Blaze
Copy link
Author

Thanks,
pom:

      <unknownVarAsFalse>true</unknownVarAsFalse>

plus source:

        // #ifndef GIT_BUILD_TIME
        // #local GIT_BUILD_TIME = "unknown"
        // #endif
        log.info("Plugin build time: /*$GIT_BUILD_TIME$*/");

works just like it should

@Lilianne-Blaze
Copy link
Author

If there are no problems with it, could you release it as 7.1.1?

@raydac
Copy link
Owner

raydac commented Jan 13, 2024

7.1.1 is out

@raydac raydac closed this as completed Jan 13, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants