apache / apache/maven-shade-plugin

[MSHADE-156] shade plugin is transforming also strings that are not supposed to be transformed

Open
#518 11 comments 0 reactions 0 assignees View on GitHub
bug priority:major
Dominant language
Java
Stars
188
Forks
103
Avg merge
16h 39m
Merged PRs (30d)
4

Description

**[Neeme Praks](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=neeme)** opened **[MSHADE-156](https://issues.apache.org/jira/browse/MSHADE-156?redirect=false)** and commented

I'm shading several third party libraries into a single JAR. In the context of this issue, there are two important libraries:

1. com.nothome:javaxdelta:2.0.1 - this library is in "at.spardat.xma.xdelta" package.
2. ch.qos.logback:logback-classic:1.0.11 - in this library, in class ch.qos.logback.classic.spi.StackTraceElementProxy, there is a method to convert stack trace elements into strings:

```
public String getSTEAsString() {
if (steAsString == null) {
steAsString = "at " + ste.toString();
}
return steAsString;
}
```

I use "org.myorgname.appname.shaded" package for shading.

During shading, the constant "at " is replaced with "org.myorgname.appname.shaded.at" -- shade plugin thinks that the "at" in the beginning of that string is a package name and shades it.

This results in an unfortunate side-effect: all logged stack traces now look like this:

```
Caused by: java.util.zip.ZipException: error in opening zip file
org.myorgname.appname.shaded.at java.util.zip.ZipFile.open(Native Method) ~[na:1.6.0_19]
org.myorgname.appname.shaded.at java.util.zip.ZipFile.(ZipFile.java:114) ~[na:1.6.0_19]
org.myorgname.appname.shaded.at java.util.zip.ZipFile.(ZipFile.java:131) ~[na:1.6.0_19]
```

Possible fixes:
* instead of just checking the first part of the package (at), check for the full package (at.spardat.xma.xdelta).
* allow to configure shade plugin to ignore certain string constants in certain classes (this would solve also some other issues we have with shade plugin being too eager).
* both of the above.

---

**Affects:** 2.1

**Issue Links:**
- [SLING-8092](https://issues.apache.org/jira/browse/SLING-8092) Relocation in Content Extension too bold
(_**"causes"**_)
- [FLINK-13044](https://issues.apache.org/jira/browse/FLINK-13044) Shading of AWS SDK in flink-s3-fs-hadoop results in ClassNotFoundExceptions
(_**"breaks"**_)

**Remote Links:**
- [GitHub Pull Request #249
](https://github.com/apache/maven-shade-plugin/pull/249)

9 votes, 15 watchers

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the Maven Shade Plugin's handling of string constants during package relocation, using the reported StackTraceElementProxy.getSTEAsString example as the reproduction case. Compare the proposed full-package matching and configurable exclusions, then verify that ordinary stack-trace strings are unchanged while legitimate package references still relocate.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.