Skip to content
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

[warning] Byte buffer backing array warning fix #7368

Merged

Conversation

hellosagar
Copy link
Contributor

Overview

Tried to fix the ByteBufferBackingArray ⚠️ which is basically is avoid us to access the .array() because there is the possibility that it could be direct ByteBuffer (built using off-heap directly mapped to memory) too.

Proposed Changes

To avoid this situation, I'm checking first if buffer.hasArray() which checks it doesn't have a null byte array, and if it's not a read-only ByteBuffer(basically checking if its a heap buffer)

Problem

Even after doing what is mentioned above, that warning still exists. But as soon as I invoke the buffer.arrayOffset()(which might throw an exception if its a heap buffer) before calling buffer.array() the warning is gone

if(buffer.hasArray()){ // It's checking if byte array is not  null and not read only.
try {
      buffer.arrayOffset(); // Also check byte array in ByteBuffer is not null and its not readomly.
    } catch (ReadOnlyBufferException e) {
      return null;
    }
// ..... further code
}

and if I don't call the buffer.arrayOffset() warning exists.

Thanks for the help in advance 🙇‍♂️

@hellosagar hellosagar changed the title ByteBufferBackingArray warning fix [warning] ByteBufferBackingArray fix Jun 9, 2022
@hellosagar hellosagar changed the title [warning] ByteBufferBackingArray fix [warning] Byte buffer backing array warning fix Jun 10, 2022
@hellosagar hellosagar force-pushed the byte-buffer-backing-array-warning-fix branch from 301004c to 7bcef77 Compare June 10, 2022 16:59
return type.decoder().decode(stringBuffer).toString();
} catch (CharacterCodingException e) {
if (type == Type.UTF16) {
if (buffer.hasArray()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's safe to suppress this warning -- we create and control all of the ByteBuffers here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah okay, Yeah we can suppress it, then the little trade-off is that now it has to keep in mind a thingy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now lme suppress it

@hellosagar hellosagar force-pushed the byte-buffer-backing-array-warning-fix branch 2 times, most recently from 6193705 to 103785a Compare June 11, 2022 08:54
@utzcoz
Copy link
Member

utzcoz commented Jun 11, 2022

@hellosagar Looks like you have pushed wrong commits to this branch, and the final result is one added line. Could you check it again?

@hellosagar
Copy link
Contributor Author

ohh yeah right, sorry

@hellosagar hellosagar force-pushed the byte-buffer-backing-array-warning-fix branch from 103785a to a66bddd Compare June 11, 2022 09:16
@utzcoz
Copy link
Member

utzcoz commented Jun 13, 2022

@hellosagar could you rebase and squash to one commit? Thanks.

@hellosagar hellosagar force-pushed the byte-buffer-backing-array-warning-fix branch from 606aa5f to c880b63 Compare June 13, 2022 07:44
@utzcoz utzcoz merged commit 2dae454 into robolectric:master Jun 13, 2022
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.

None yet

3 participants