Thanks to visit codestin.com
Credit goes to github.com

Skip to content

In a modular application, sun.misc.Unsafe is a problem #6913

Description

@io7m

Describe the bug

When running an application that exclusively uses the module path, and places its own modules plus those of OpenTelemetry on the module path, I get errors like this:

   cardant: WARN: io.opentelemetry.sdk.metrics.export.PeriodicMetricReader: Exporter threw an Exception
   java.lang.NoClassDefFoundError: Could not initialize class io.opentelemetry.exporter.internal.marshal.UnsafeString
           at [email protected]/io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil.getUtf8Size(StatelessMarshalerUtil.java:308)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil.getUtf8Size(StatelessMarshalerUtil.java:303)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil.sizeStringWithContext(StatelessMarshalerUtil.java:98)
           at [email protected]/io.opentelemetry.exporter.internal.otlp.metrics.MetricStatelessMarshaler.getBinarySerializedSize(MetricStatelessMarshaler.java:202)
           at [email protected]/io.opentelemetry.exporter.internal.otlp.metrics.MetricStatelessMarshaler.getBinarySerializedSize(MetricStatelessMarshaler.java:28)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil.sizeRepeatedMessageWithContext(StatelessMarshalerUtil.java:135)
           at [email protected]/io.opentelemetry.exporter.internal.otlp.metrics.InstrumentationScopeMetricsStatelessMarshaler.getBinarySerializedSize(InstrumentationScopeMetricsStatelessMarshaler.java:58)
           at [email protected]/io.opentelemetry.exporter.internal.otlp.metrics.InstrumentationScopeMetricsStatelessMarshaler.getBinarySerializedSize(InstrumentationScopeMetricsStatelessMarshaler.java:22)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil$RepeatedElementPairSizeCalculator.accept(StatelessMarshalerUtil.java:263)
           at java.base/java.util.IdentityHashMap.forEach(Unknown Source)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil.sizeRepeatedMessageWithContext(StatelessMarshalerUtil.java:188)
           at [email protected]/io.opentelemetry.exporter.internal.otlp.metrics.ResourceMetricsStatelessMarshaler.getBinarySerializedSize(ResourceMetricsStatelessMarshaler.java:70)
           at [email protected]/io.opentelemetry.exporter.internal.otlp.metrics.ResourceMetricsStatelessMarshaler.getBinarySerializedSize(ResourceMetricsStatelessMarshaler.java:28)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil$RepeatedElementPairSizeCalculator.accept(StatelessMarshalerUtil.java:263)
           at java.base/java.util.IdentityHashMap.forEach(Unknown Source)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.StatelessMarshalerUtil.sizeRepeatedMessageWithContext(StatelessMarshalerUtil.java:188)
           at [email protected]/io.opentelemetry.exporter.internal.otlp.metrics.LowAllocationMetricsRequestMarshaler.calculateSize(LowAllocationMetricsRequestMarshaler.java:84)
           at [email protected]/io.opentelemetry.exporter.internal.otlp.metrics.LowAllocationMetricsRequestMarshaler.initialize(LowAllocationMetricsRequestMarshaler.java:57)
           at [email protected]/io.opentelemetry.exporter.internal.otlp.metrics.MetricReusableDataMarshaler.export(MetricReusableDataMarshaler.java:45)
           at [email protected]/io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter.export(OtlpGrpcMetricExporter.java:107)
           at [email protected]/io.opentelemetry.sdk.metrics.export.PeriodicMetricReader$Scheduled.doRun(PeriodicMetricReader.java:167)
           at [email protected]/io.opentelemetry.sdk.metrics.export.PeriodicMetricReader$Scheduled.run(PeriodicMetricReader.java:153)
           at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
           at java.base/java.util.concurrent.FutureTask.runAndReset(Unknown Source)
           at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
           at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
           at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
           at java.base/java.lang.Thread.run(Unknown Source)
   Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: sun/misc/Unsafe [in thread "PeriodicMetricReader-1"]
           at [email protected]/io.opentelemetry.exporter.internal.marshal.UnsafeAccess$UnsafeHolder.getUnsafe(UnsafeAccess.java:85)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.UnsafeAccess$UnsafeHolder.<clinit>(UnsafeAccess.java:77)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.UnsafeAccess.arrayBaseOffset(UnsafeAccess.java:64)
           at [email protected]/io.opentelemetry.exporter.internal.marshal.UnsafeString.<clinit>(UnsafeString.java:13)
           ... 28 common frames omitted

Previously, I'd get a warning about a missing sun.misc.Unsafe class, but everything would still work correctly.

Steps to reproduce

It seems like placing the OpenTelemetry artifacts on the module path is enough to trigger this.

What did you expect to see?

No exceptions.

What did you see instead?

A rather nasty exception, and no telemetry being sent.

What version and what artifacts are you using?

1.44.1.

https://github.com/io7m-com/cardant/blob/db0178a55f80d2a5f729da6cb22af56ebdfa5a94/pom.xml#L530

Environment

openjdk version "23" 2024-09-17
OpenJDK Runtime Environment (build 23)
OpenJDK 64-Bit Server VM (build 23, mixed mode, sharing)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions