Title: Set Java 8 release compiler option by ryandens · Pull Request #334 · hypertrace/javaagent · GitHub
Open Graph Title: Set Java 8 release compiler option by ryandens · Pull Request #334 · hypertrace/javaagent
X Title: Set Java 8 release compiler option by ryandens · Pull Request #334 · hypertrace/javaagent
Description: Use --release flag to target JDK 8 bytecode compatibility My recent change to capture HTTP requests contained a fascinating bug resulting in the bug-fix not working when running on JVMs <= 1.8 due to a NoSuchMethodError being thrown when this line executes. This was incredibly surprising to me, because the position(int) API exists on Buffer (the superclass of ByteBuffer ) in java 1.8, so why do we have problems here? Confused, I did a quick google search and found an incredibly helpful article right away: ByteBuffer and the Dreaded NoSuchMethodError. The tl;dr of this change is that, the bytecode we produce prior to this change looked like this: BEFORE public static void handleRead(java.nio.ByteBuffer, int, org.hypertrace.agent.core.instrumentation.SpanAndBuffer); descriptor: (Ljava/nio/ByteBuffer;ILorg/hypertrace/agent/core/instrumentation/SpanAndBuffer;)V flags: (0x0009) ACC_PUBLIC, ACC_STATIC Code: stack=3, locals=6, args_size=3 0: iload_1 1: ifgt 5 4: return 5: aload_0 6: aload_0 7: invokevirtual #23 // Method java/nio/ByteBuffer.position:()I 10: iload_1 11: isub 12: invokevirtual #24 // Method java/nio/ByteBuffer.position:(I)Ljava/nio/ByteBuffer; AFTER public static void handleRead(java.nio.ByteBuffer, int, org.hypertrace.agent.core.instrumentation.SpanAndBuffer); descriptor: (Ljava/nio/ByteBuffer;ILorg/hypertrace/agent/core/instrumentation/SpanAndBuffer;)V flags: (0x0009) ACC_PUBLIC, ACC_STATIC Code: stack=3, locals=6, args_size=3 0: iload_1 1: ifgt 5 4: return 5: aload_0 6: aload_0 7: invokevirtual #23 // Method java/nio/ByteBuffer.position:()I 10: iload_1 11: isub 12: invokevirtual #24 // Method java/nio/ByteBuffer.position:(I)Ljava/nio/Buffer; Spot the difference? The bytecode for this snippet is identical, but when compiled without the --release 8, the invokevirtual #24 call refers to a method reference in the constant pool with a signature matching the descriptor Method java/nio/ByteBuffer.position:(I)Ljava/nio/ByteBuffer. However, when we compile it with the --release 8 flag the method reference in the constant pool is Method java/nio/ByteBuffer.position:(I)Ljava/nio/Buffer. This resolves the cross-jre compatibility issue of using the ByteBuffer.position(int) API because Method java/nio/ByteBuffer.position:(I)Ljava/nio/ByteBuffer does not exist on JDK 1.8 or below. Other notes It's worth noting that this has impacted many well-known open source projects. The blog i linked above links to several other projects that encountered this exact issue: Eclipse Jetty Apache Pulsar Eclipse Vert.x Apache Thrift the Yugabyte DB client Debezium (the project the author found the bug on) The author also evaluated other methods of resolving this issue and verifying that it couldn't happen again, and determined the --release flag was the best option: Note that theoretically you could achieve the same effect also when using --source and --target; by means of the --boot-class-path option, you could advise the compiler to use a specific set of bootstrap class files instead of those from the JDK used for compilation. But that’d be quite a bit more cumbersome as it requires you to actually provide the classes of the targeted Java version, whereas --release will make use of the signature data coming with the currently used JDK itself.
Open Graph Description: Use --release flag to target JDK 8 bytecode compatibility My recent change to capture HTTP requests contained a fascinating bug resulting in the bug-fix not working when running on JVMs <= 1.8 d...
X Description: Use --release flag to target JDK 8 bytecode compatibility My recent change to capture HTTP requests contained a fascinating bug resulting in the bug-fix not working when running on JVMs <= 1...
Opengraph URL: https://github.com/hypertrace/javaagent/pull/334
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:36514263-a652-207b-3cda-9a79073e56e2 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 84B2:3A6932:8238E9:B13DB5:6A4DD672 |
| html-safe-nonce | b53a1f8ba68a7ee23d404b73142132cb2ffcfe5e8afe321555cdfb5c859d5c80 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NEIyOjNBNjkzMjo4MjM4RTk6QjEzREI1OjZBNERENjcyIiwidmlzaXRvcl9pZCI6Ijg2ODA1NDM4NDgwODQ5MTk5MjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 21b598207668b924ad5b3d8265ac2cb856c8104c010fb70ee91c6ba32d57be12 |
| hovercard-subject-tag | pull_request:688194621 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/hypertrace/javaagent/pull/334/files |
| twitter:image | https://avatars.githubusercontent.com/u/8192732?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/8192732?s=400&v=4 |
| og:image:alt | Use --release flag to target JDK 8 bytecode compatibility My recent change to capture HTTP requests contained a fascinating bug resulting in the bug-fix not working when running on JVMs <= 1.8 d... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/hypertrace/javaagent git https://github.com/hypertrace/javaagent.git |
| octolytics-dimension-user_id | 65374698 |
| octolytics-dimension-user_login | hypertrace |
| octolytics-dimension-repository_id | 302314733 |
| octolytics-dimension-repository_nwo | hypertrace/javaagent |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 302314733 |
| octolytics-dimension-repository_network_root_nwo | hypertrace/javaagent |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1d344bdb7547fe6bca17a59bb2b8aac3dc9532a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width