Skip to content

ManifestResourceProvider logs warning with java -cp MainClass #14523

@kelunik

Description

@kelunik

Describe the bug

ManifestResourceProvider logs a warning due to MainJarPathFinder if the application is started with java -cp ... com.example.Main instead of java -jar yourapp.jar.

In this case, sun.java.command contains the main class name, not the JAR name, so trying to read the main class name as ZIP obviously fails.

Steps to reproduce

Start application with auto-configuration and java -cp MainClass.

You additionally need a file named like the main class in the current working directory, see:

In my case, I have a bash file generated and named like the main class to start different services (batch jobs) from the same JAR.

Expected behavior

No warning logged.

Actual behavior

Error reading manifest
java.util.zip.ZipException: zip END header not found
	at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1649)
	at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1657)
	at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1495)
	at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1458)
	at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:724)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:251)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:180)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:345)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:316)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:296)
	at io.opentelemetry.instrumentation.resources.ManifestResourceProvider.readManifest(ManifestResourceProvider.java:73)
	at java.base/java.util.Optional.flatMap(Optional.java:289)
	at io.opentelemetry.instrumentation.resources.ManifestResourceProvider$1.readData(ManifestResourceProvider.java:42)
	at io.opentelemetry.instrumentation.resources.AttributeResourceProvider.createResource(AttributeResourceProvider.java:70)
	at io.opentelemetry.sdk.autoconfigure.ResourceConfiguration.configureResource(ResourceConfiguration.java:142)
	at io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder.build(AutoConfiguredOpenTelemetrySdkBuilder.java:449)
	at app.observability.OpenTelemetry.configureSdk(OpenTelemetry.java:78)
	at app.Foo.main(Foo.java:45)

Javaagent or library instrumentation version

1.51.0

Environment

JDK: 21.0.8
OS: Linux

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds triageNew issue that requires triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions