Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starter jars not excluded from repackaged jars using spring-boot-maven-plugin. #24594

Closed
edwardsre opened this issue Dec 22, 2020 · 3 comments
Closed
Labels
status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@edwardsre
Copy link
Contributor

edwardsre commented Dec 22, 2020

JarTypeFilter is not handling dependency jars with missing manifest files. This results in all starter jars being included in the repackaged jar.

A NullPointerException is thrown from JarTypeFilter.filter on this line:

    String jarType = jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Jar-Type");

When this occurs, the NPE is caught in FilterArtifacts.filter which skips the results of the executing filter, resulting in the starter jars being retained in the repackaged jar file.

If the manifest file is missing, the jar should still be included by this filter (returning false). Either of these fix the issue...

	return Optional.ofNullable(jarFile.getManifest())
			.map(Manifest::getMainAttributes)
			.map(attributes -> attributes.getValue("Spring-Boot-Jar-Type"))
			.map(EXCLUDED_JAR_TYPES::contains)
			.orElse(Boolean.FALSE);

or

	final Manifest manifest = jarFile.getManifest();
	if (manifest != null) {
		String jarType = manifest.getMainAttributes().getValue("Spring-Boot-Jar-Type");
		return jarType != null && EXCLUDED_JAR_TYPES.contains(jarType);
	}
	return false;

This jar was the culprit in our project. net.sourceforge.streamsupport:streamsupport:1.2.1.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 22, 2020
@edwardsre edwardsre changed the title Starter jars are not excluded from repackaged jars using the spring-boot-maven-plugin. Starter jars not excluded from repackaged jars using spring-boot-maven-plugin. Dec 22, 2020
@dreis2211
Copy link
Contributor

Nice find @edwardsre. If I remember correctly, my original PR for this included a catch on every Exception - not just IOException - which the Gradle part still does for example: see JarTypeFileSpec. I guess the third alternative is to harmonize this on the Maven side of things. I'd be happy to open a PR if you don't mind to fix this, but I don't want to steal your chance to provide a PR yourself. Just let me know.

@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 22, 2020
@snicoll snicoll added this to the 2.4.x milestone Dec 22, 2020
edwardsre added a commit to edwardsre/spring-boot that referenced this issue Dec 22, 2020
JarTypeFilter was not handling dependency jars with missing manifest files, resulting in all starter jars being included in repackaged jars.

Fixes spring-projectsgh-24594
@edwardsre
Copy link
Contributor Author

Nice find @edwardsre. If I remember correctly, my original PR for this included a catch on every Exception - not just IOException - which the Gradle part still does for example: see JarTypeFileSpec. I guess the third alternative is to harmonize this on the Maven side of things. I'd be happy to open a PR if you don't mind to fix this, but I don't want to steal your chance to provide a PR yourself. Just let me know.

Thanks @dreis2211. I submitted a PR using the Optional approach.

@snicoll
Copy link
Member

snicoll commented Dec 23, 2020

Very nice @edwardsre, thank you very much for the detective work and the PR.

@dreis2211 thanks for the follow-up, it is very much appreciated.

Closing in favour of PR #24597

@snicoll snicoll closed this as completed Dec 23, 2020
@snicoll snicoll added the status: superseded An issue that has been superseded by another label Dec 23, 2020
@snicoll snicoll removed this from the 2.4.x milestone Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants