-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Cast ByteBuffer to Buffer before calling position(int) #26614
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
Conversation
Unrelated restore error - will retry in a bit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to fill out the template?
Yeah, gonna do that & send email once CI is green |
How does this fix actually work? Have we tested it on Android 9 or earlier? ByteBuffer is a Buffer, so if the position doesn't exist on the ByteBuffer object, it still wouldn't exist on ByteBuffer object after it was cast to a Buffer unless there's some implicit conversion going on that I'm unaware of. AFAIK Java doesn't have the equivalent of C#'s
Not exactly. Looking at how msgpack/msgpack-java#516 was resolved, it looks like they fixed it by compiling against an older version of Java. It seems that the real breaking change was Buffer.position(int) switching from final to virtual between Java 8 and Java 9, so it makes sense that compiling using an older Java would fix that. I'm not sure how casting to Buffer would fix that since the runtime would still be looking for a virtual Buffer.position(int) and "No virtual method position(I)" (emphasis mine) would exist either before or after the cast to Buffer on Android 9 because Buffer.position(int) is final on older runtimes. |
It's not that |
👍 Now it makes sense to me. |
Hello human! Please make sure you've included the Shiproom Template in a comment or (preferably) the PR description. Also, make sure this PR is not marked as a draft and is ready-to-merge. |
Resolves #26552
Description
In Java 11,
ByteBuffer.position(int)
is overridden to return a ByteBuffer rather than a Buffer, which causes errors on Android that look like:The workaround is to cast to
Buffer
before callingposition(int)
so that we get the implementation from the superclassBuffer
, which returns aBuffer
as it does in Java 7/8. Thanks to @aaronoe for reporting this. I sent him a local build with this change, and he confirmed that it works on Android 9 & below.Customer Impact
Allows the Your Phone team to continue working to adopt the Java SignalR client.
Regression?
No, this bug existed in our initial implementation of the MessagePack protocol.
Risk
Low, our test suite still passes and the Your Phone team confirmed that the fix worked for them. Behavior should remain as intended.