gnodet-bot commented on code in PR #422:
URL: https://github.com/apache/maven-archiver/pull/422#discussion_r4719482015
##########
src/main/java/org/apache/maven/shared/archiver/MavenArchiver.java:
##########
@@ -109,21 +95,12 @@ public class MavenArchiver {
"${artifact.groupIdPath}/${artifact.artifactId}/" +
"${artifact.baseVersion}/${artifact.artifactId}-"
+
"${artifact.baseVersion}${dashClassifier?}.${artifact.extension}";
- private static final List<String> ARTIFACT_EXPRESSION_PREFIXES;
-
private static final Pattern SPECIFICATION_VERSION_PATTERN =
Pattern.compile("([0-9]+\\.[0-9]+)(.*?)");
private static final Pattern NON_ALPHANUM =
Pattern.compile("[^A-Za-z0-9]");
Review Comment:
⚠️ **Dead code: `NON_ALPHANUM`, `REPEATING_DOTS`, `isValidModuleName()`,
`cleanModuleName()`**
These four declarations are now unreachable — `createArchive()` was their
only caller and it has been removed. `getManifest()` is now the canonical API,
but it never calls them, so the sanitization of `Automatic-Module-Name`
silently stopped happening.
Pick one of:
**(a) Move sanitization into `getManifest()`** (recommended — keeps the
guarantee intact):
```java
// At the end of getManifest(Session, Project, MavenArchiveConfiguration),
before `return manifest`:
String amn = manifest.getMainAttributes().getValue("Automatic-Module-Name");
if (amn != null) {
if (amn.isEmpty() || !isValidModuleName(amn)) {
String sanitized = amn.isEmpty() ? "" : cleanModuleName(amn);
if (sanitized.isEmpty() || !isValidModuleName(sanitized)) {
LOGGER.warn("Invalid Automatic-Module-Name '{}' cannot be
sanitized — removing it", amn);
manifest.getMainAttributes().remove(new
Attributes.Name("Automatic-Module-Name"));
} else {
LOGGER.warn("Automatic-Module-Name '{}' sanitized to '{}'", amn,
sanitized);
manifest.getMainAttributes().putValue("Automatic-Module-Name",
sanitized);
}
}
}
```
**(b) Make them `public`** so that companion plugin PRs can call them
explicitly.
**(c) Delete them** — but only if `Automatic-Module-Name` sanitization is
intentionally being dropped (the PR description does not say this).
Leaving unreachable package-private code is the worst option — it looks like
the feature exists but it is bypassed entirely.
<!-- reviewer: gnodet-bot -->
##########
src/test/java/org/apache/maven/shared/archiver/MavenArchiverTest.java:
##########
@@ -391,91 +238,44 @@ void newlinesInManifestEntryGetReplacedWithSpaces()
throws Exception {
}
@Test
- void manifestEntryWithEmptyLinesDoesNotCorruptManifest() throws Exception {
- File jarFile = new File("target/test/dummy.jar");
- JarArchiver jarArchiver = getCleanJarArchiver(jarFile);
-
- MavenArchiver archiver = getMavenArchiver(jarArchiver);
-
- ProjectStub project = getDummyProject();
- MavenArchiveConfiguration config = new MavenArchiveConfiguration();
- config.setForced(true);
- config.addManifestEntry("WithEmptyLine", "para1\n\npara3");
- config.addManifestEntry("Normal", "value");
-
- archiver.createArchive(session, project, config);
- assertThat(jarFile).exists();
-
- Manifest manifest = getJarFileManifest(jarFile);
- Attributes attributes = manifest.getMainAttributes();
- assertThat(attributes.getValue("WithEmptyLine")).isEqualTo("para1
para3");
- assertThat(attributes.getValue("Normal")).isEqualTo("value");
- }
-
- @Test
- void manifestEntryWithMultipleEmptyLinesDoesNotCorruptSubsequentEntries()
throws Exception {
- File jarFile = new File("target/test/dummy.jar");
- JarArchiver jarArchiver = getCleanJarArchiver(jarFile);
-
- MavenArchiver archiver = getMavenArchiver(jarArchiver);
-
+ void carriageReturnInManifestEntry() throws Exception {
Review Comment:
⚠️ **Three sanitization edge-case tests removed without manifest-only
replacements**
`manifestEntryWithEmptyLinesDoesNotCorruptManifest`,
`manifestEntryWithMultipleEmptyLinesDoesNotCorruptSubsequentEntries`, and
`manifestEntryWithCRLFEmptyLinesDoesNotCorruptManifest` were deleted. These
exercised `sanitizeManifestValue()` on `\n\n`, `\r\n\r\n`, and `\r` inputs
respectively — all still active code paths.
Compare with how `carriageReturnInManifestEntry` just below was rewritten to
call `getManifest()` directly (no `JarArchiver`, no filesystem I/O). The three
removed tests should receive the same treatment: a lightweight manifest-only
test using the new API and `SessionMock`.
Without them, a regression in multi-empty-line or CRLF handling would go
undetected.
<!-- reviewer: gnodet-bot -->
##########
src/main/java/org/apache/maven/shared/archiver/MavenArchiver.java:
##########
@@ -321,7 +281,7 @@ protected Manifest doGetManifest(
String layoutType = config.getClasspathLayoutType();
String layout = config.getCustomClasspathLayout();
- Interpolator interpolator = new StringSearchInterpolator();
+ Interpolator interpolator = session.getService(Interpolator.class);
Review Comment:
ℹ️ **Potential NPE when `session` is null and `addClasspath` is true**
`session.getService(Interpolator.class)` at this line will throw
`NullPointerException` if `session` is `null` and `addClasspath` is `true`.
Compare with `handleBuildEnvironmentEntries`, which already guards:
```java
if (session != null) { ... }
```
Either add a null guard here (and skip classpath interpolation silently or
use a no-op interpolator), or annotate the `session` parameter of all public
`getManifest()` overloads with `@Nonnull` and document that null session +
addClasspath=true is a programming error. The current contract is inconsistent.
<!-- reviewer: gnodet-bot -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]