Skip to content

Replace Xlint deprecation check with custom errorprone check#8061

Merged
jack-berg merged 6 commits intoopen-telemetry:mainfrom
trask:deprecate-with-errorprone
Feb 13, 2026
Merged

Replace Xlint deprecation check with custom errorprone check#8061
jack-berg merged 6 commits intoopen-telemetry:mainfrom
trask:deprecate-with-errorprone

Conversation

@trask
Copy link
Member

@trask trask commented Feb 8, 2026

Motivated by #8060 (well, that and the many PRs in the instrumentation repo where this has plagued me recently)

Context:

When compiling with --release 8, javac's -Xlint:deprecation warns on imports of deprecated classes (JDK-8032211). Since @SuppressWarnings cannot suppress import-level warnings, this forced us to use fully-qualified class names as a workaround.

}

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "deprecation"}) // deprecation: EXTENDED_ATTRIBUTES
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's slightly more strict than javac here, but this does align with Intellij's warnings, so seems good

@trask trask force-pushed the deprecate-with-errorprone branch 5 times, most recently from e79ae1d to cfd48d7 Compare February 8, 2026 05:18
@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

❌ Patch coverage is 27.27273% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.23%. Comparing base (73d0833) to head (3749e03).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...ntelemetry/sdk/testing/logs/TestLogRecordData.java 0.00% 3 Missing ⚠️
...sting/logs/internal/TestExtendedLogRecordData.java 0.00% 3 Missing ⚠️
...entelemetry/sdk/logs/ExtendedSdkLogRecordData.java 0.00% 1 Missing ⚠️
...va/io/opentelemetry/sdk/logs/SdkLogRecordData.java 0.00% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (27.27%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8061      +/-   ##
============================================
+ Coverage     90.18%   90.23%   +0.04%     
- Complexity     7591     7594       +3     
============================================
  Files           841      841              
  Lines         22911    22911              
  Branches       2288     2291       +3     
============================================
+ Hits          20663    20673      +10     
+ Misses         1531     1521      -10     
  Partials        717      717              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jack-berg
Copy link
Member

This requirement to avoid importing deprecating classes has annoyed me for a while. I'm supportive if you can get the build to pass on java 21, 25 😛

@trask trask force-pushed the deprecate-with-errorprone branch from 6ebdc89 to 86e4227 Compare February 10, 2026 21:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces javac's -Xlint:deprecation with a custom ErrorProne check to address JDK-8032211, where javac warns on imports of deprecated classes when compiling with --release 8. Since @SuppressWarnings cannot suppress import-level warnings, the solution is to disable -Xlint:deprecation and implement a custom ErrorProne check (OtelDeprecatedApiUsage) that properly honors @SuppressWarnings annotations, including for imports.

Changes:

  • Added custom ErrorProne check OtelDeprecatedApiUsage to detect deprecated API usage while properly supporting @SuppressWarnings
  • Disabled -Xlint:deprecation in Gradle build configuration
  • Replaced fully-qualified class names with simple imports throughout the codebase for deprecated classes like Body, InstrumentationLibraryInfo, JaegerPropagator, OtTracePropagator, and ZipkinSpanExporter

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 29 comments.

Show a summary per file
File Description
custom-checks/src/main/java/io/opentelemetry/gradle/customchecks/OtelDeprecatedApiUsage.java New ErrorProne check that detects deprecated API usage while properly honoring @SuppressWarnings, including for imports
custom-checks/src/test/java/io/opentelemetry/gradle/customchecks/OtelDeprecatedApiUsageTest.java Comprehensive test suite for the new check covering positive/negative cases, suppressions, and edge cases
custom-checks/src/main/resources/META-INF/services/com.google.errorprone.bugpatterns.BugChecker Registers the new OtelDeprecatedApiUsage check with ErrorProne
buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts Disables -Xlint:deprecation and documents the reason
sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/internal/TestExtendedLogRecordData.java Adds import for deprecated Body class and replaces fully-qualified names with simple names
sdk/testing/src/main/java/io/opentelemetry/sdk/testing/logs/TestLogRecordData.java Adds import for deprecated Body class and replaces fully-qualified names with simple names
sdk/logs/src/main/java/io/opentelemetry/sdk/logs/SdkLogRecordData.java Adds import for deprecated Body class and replaces fully-qualified names with simple names
sdk/logs/src/main/java/io/opentelemetry/sdk/logs/ExtendedSdkLogRecordData.java Adds import for deprecated Body class and replaces fully-qualified names with simple names
sdk/common/src/test/java/io/opentelemetry/sdk/common/internal/InstrumentationScopeUtilTest.java Adds import for deprecated InstrumentationLibraryInfo and replaces fully-qualified names
sdk/common/src/test/java/io/opentelemetry/sdk/common/InstrumentationLibraryInfoTest.java Adds import and replaces fully-qualified names for InstrumentationLibraryInfo in comments and code
sdk/common/src/main/java/io/opentelemetry/sdk/common/internal/InstrumentationScopeUtil.java Adds import for deprecated InstrumentationLibraryInfo and replaces fully-qualified names
sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/SpanExporterConfigurationTest.java Adds import for deprecated ZipkinSpanExporter and replaces fully-qualified name
sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/FullConfigTest.java Adds imports for deprecated JaegerPropagator and OtTracePropagator, replaces fully-qualified names
sdk-extensions/autoconfigure/src/testFullConfig/java/io/opentelemetry/sdk/autoconfigure/ConfigurableSpanExporterTest.java Adds import for deprecated ZipkinSpanExporter and replaces fully-qualified names
extensions/trace-propagators/src/test/java/io/opentelemetry/extension/trace/propagation/JaegerPropagatorTest.java Adds import and replaces fully-qualified names for deprecated JaegerPropagator
extensions/trace-propagators/src/main/java/io/opentelemetry/extension/trace/propagation/JaegerConfigurablePropagator.java Adds import and replaces fully-qualified names for deprecated JaegerPropagator in javadoc and code
extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextInjectBenchmark.java Adds import and replaces fully-qualified name for deprecated JaegerPropagator
extensions/trace-propagators/src/jmh/java/io/opentelemetry/extension/trace/propagation/PropagatorContextExtractBenchmark.java Adds import and replaces fully-qualified names for deprecated JaegerPropagator
exporters/zipkin/src/test/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProviderTest.java Adds import for deprecated ZipkinSpanExporter and replaces fully-qualified name
exporters/zipkin/src/main/java/io/opentelemetry/exporter/zipkin/internal/ZipkinSpanExporterProvider.java Adds imports for deprecated ZipkinSpanExporter and ZipkinSpanExporterBuilder, replaces fully-qualified names
api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributesBuilder.java Adds explanatory comment to @SuppressWarnings about deprecated EXTENDED_ATTRIBUTES
api/incubator/src/main/java/io/opentelemetry/api/incubator/common/ArrayBackedExtendedAttributes.java Adds explanatory comment to @SuppressWarnings about deprecated EXTENDED_ATTRIBUTES

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@jack-berg jack-berg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small improvement recommendation, but looks good. Thanks!

@jack-berg jack-berg merged commit 8a1d9e0 into open-telemetry:main Feb 13, 2026
26 of 27 checks passed
Copilot AI added a commit to open-telemetry/opentelemetry-java-contrib that referenced this pull request Feb 13, 2026
This ports open-telemetry/opentelemetry-java#8061 to opentelemetry-java-contrib.

- Created custom-checks module with OtelDeprecatedApiUsage ErrorProne check
- Added comprehensive test suite for the check
- Registered the check with ErrorProne via META-INF/services
- Updated buildSrc to include custom-checks dependency
- Disabled -Xlint:deprecation in favor of the custom check
- Added error_prone_test_helpers to dependency management

Co-authored-by: trask <218610+trask@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants