maven-compiler-plugin icon indicating copy to clipboard operation
maven-compiler-plugin copied to clipboard

[MCOMPILER-592] IndexOutOfBoundsException when project.build.outputTimestamp is empty

Open jira-importer opened this issue 1 year ago • 3 comments

Thijs Rijpert opened MCOMPILER-592 and commented

Due to a combination of plugins, it is possible for the project.build.outputTimestamp property to have an empty string as a value. This causes an IndexOutOfBoundsException on line 1242 when it tries to access the first character in the string.

This can be fixed by doing an isEmpty check before doing the charAt check. I will create an PR for this.

While this bug is caused by another plugin, I think this should be fixed in the compiler because the error returned (IndexOutOfBoundsException), is vague and hard to debug.

The workaround for this issue is setting the project.build.outputTimestamp property with an arbitrary value.


Affects: 3.12.0, 3.12.1, 3.13.0

Remote Links:

jira-importer avatar May 31 '24 08:05 jira-importer

Michael Osipov commented

How come that it is empty? Manually?

jira-importer avatar May 31 '24 08:05 jira-importer

Sergey Ponomarev commented

This was fixed and merged so can be closed. But I think we should remove the useless validation that caused the exception https://github.com/apache/maven-compiler-plugin/pull/266

jira-importer avatar Oct 05 '24 20:10 jira-importer

Sergey Ponomarev commented

The outputTimestamp.length() > 1 really confused me. The one char (not digit) will make the outputTimestamp ignored as if it was empty.

It looks like I understood why the one char will be ignored. In JIRA I found this: "disable it <project.build.outputTimestamp>x</project.build.outputTimestamp>".

In the maven-archiver https://github.com/apache/maven-archiver/blob/master/src/main/java/org/apache/maven/archiver/MavenArchiver.java#L703 there is more explanation

// no timestamp configured (1 character configuration is useful to override a full value during pom
// inheritance)
if (outputTimestamp.length() < 2) {
    return Optional.empty();
}

So my PR is invalid. But the x value needs to be specified clearly maybe if not in code but at least in comments and documentation. I would rather introduce a special constant value like NO_INHERIT or something like that.

jira-importer avatar Oct 09 '24 07:10 jira-importer