Copilot commented on code in PR #862:
URL: 
https://github.com/apache/maven-shade-plugin/pull/862#discussion_r4366929820


##########
src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java:
##########
@@ -46,8 +46,11 @@ public boolean canTransformResource(String r) {
     @Override
     public void processResource(String resource, InputStream is, 
List<Relocator> relocators, long time)
             throws IOException {
+        int previousSize = data.size();
         IOUtil.copy(is, data);
-        data.write('\n');
+        if (data.size() > previousSize && data.toByteArray()[data.size() - 1] 
!= '\n') {

Review Comment:
   When all matching inputs are empty, this guard leaves `data` empty, so 
`hasTransformedResource()` remains false. `DefaultShader` consumes those inputs 
but then skips `modifyOutputStream()`, causing the resource to disappear from 
the shaded JAR rather than preserving an empty entry. Track whether a resource 
was processed independently of the buffer size, and add an empty-only 
regression test.



##########
src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java:
##########
@@ -46,8 +46,11 @@ public boolean canTransformResource(String r) {
     @Override
     public void processResource(String resource, InputStream is, 
List<Relocator> relocators, long time)
             throws IOException {
+        int previousSize = data.size();
         IOUtil.copy(is, data);
-        data.write('\n');
+        if (data.size() > previousSize && data.toByteArray()[data.size() - 1] 
!= '\n') {

Review Comment:
   `toByteArray()` copies the entire accumulated resource on every nonempty 
append just to inspect its final byte. For N equal-sized inputs, this 
introduces quadratic copying and allocation instead of the previous linear 
append cost, increasing build time and garbage collection pressure for projects 
merging many resources. Inspect only the incoming resource's bytes, or track 
the last byte during copying, without repeatedly cloning the accumulated buffer.



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