Copilot commented on code in PR #564:
URL: https://github.com/apache/maven-ear-plugin/pull/564#discussion_r4360146087


##########
src/main/java/org/apache/maven/plugins/ear/AbstractEarModule.java:
##########
@@ -334,13 +334,15 @@ protected void startModuleElement(XMLWriter writer, 
Boolean generateId) {
             // FIXME: Should we use the mapping using outputFileNameMapping 
instead
             // of doing this on our own?
             Artifact theArtifact = getArtifact();
-            String generatedId = theArtifact.getType().toUpperCase() + "_" + 
theArtifact.getGroupId() + "."
-                    + theArtifact.getArtifactId();
-            if (null != theArtifact.getClassifier()
-                    && !theArtifact.getClassifier().trim().isEmpty()) {
-                generatedId += "-" + theArtifact.getClassifier().trim();
+            if (theArtifact != null) {
+                String generatedId = theArtifact.getType().toUpperCase() + "_" 
+ theArtifact.getGroupId() + "."
+                        + theArtifact.getArtifactId();

Review Comment:
   `String#toUpperCase()` is locale-sensitive. For stable, deterministic IDs 
across environments, use `toUpperCase(Locale.ROOT)` (and add the `Locale` 
import).



##########
src/test/java/org/apache/maven/plugins/ear/EarModuleTest.java:
##########
@@ -40,4 +46,22 @@ void testCleanArchivePath() {
         assertEquals("", AbstractEarModule.cleanArchivePath(""));
         assertNull(AbstractEarModule.cleanArchivePath(null));
     }
+
+    @Test
+    void testStartModuleElementWithoutResolvedArtifact() {
+        StringWriter output = new StringWriter();
+        XMLWriter writer = new PrettyPrintXMLWriter(output);
+        TestableWebModule module = new TestableWebModule();
+
+        assertDoesNotThrow(() -> module.start(writer));
+        writer.endElement();
+
+        assertFalse(output.toString().contains("id="));

Review Comment:
   This assertion is brittle because it depends on an exact substring 
(`\"id=\"`) and may miss cases like whitespace (`id =`) or different 
quoting/formatting. Prefer parsing the produced XML and asserting the attribute 
is absent, or at least use a regex that matches an `id` attribute boundary 
(e.g., `\\bid\\s*=`) to reduce false negatives.



-- 
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]

Reply via email to