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

Add method java.lang.String.getBytes(byte[], int, byte) #136

Merged
merged 1 commit into from
Aug 2, 2018

Conversation

gayanW
Copy link
Collaborator

@gayanW gayanW commented Aug 1, 2018

Add method java.lang.String.getBytes(byte[], int, byte) to MJI model class for java.lang.String

This also fixes #134:

[junit] java.lang.NoSuchMethodError: java.lang.String.getBytes([BIB)V
[junit] at java.lang.AbstractStringBuilder.putStringAt(AbstractStringBuilder.java:1641)

if (coder() == coder) {
System.arraycopy(value, 0, dst, dstBegin << coder, value.length);
} else {
StringLatin1.inflate(value, 0, dst, dstBegin, value.length);
Copy link
Member

Choose a reason for hiding this comment

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

This seems to cover two cases:

  1. Both encodings (source, target) are the same.
  2. The target encoding is UTF-8 but the source is Latin-1.

However, what about the case that the source encoding is UTF-8 and the target is Latin-1?

Copy link
Member

Choose a reason for hiding this comment

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

If you are sure that the other case never occurs, please write an assertion that checks this (with an assertion message explaining this).

Copy link
Collaborator Author

@gayanW gayanW Aug 2, 2018

Choose a reason for hiding this comment

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

The official doc comment include this:

Invoker guarantees: dst is in UTF16 (inflate itself for asb), if two coders are different, and dst is big enough (range check)

The method is also package-private. Anyway, I could add an assertion that checks whether the target is in UTF16.

@cyrille-artho
Copy link
Member

Yes, please add an assertion check and put your comment as a comment in the code.

@gayanW gayanW self-assigned this Aug 2, 2018
Add method java.lang.String.getBytes(byte[], int, byte) to MJI model class for java.lang.String

This also fixes:

[junit] java.lang.NoSuchMethodError: java.lang.String.getBytes([BIB)V
[junit] at java.lang.AbstractStringBuilder.putStringAt(AbstractStringBuilder.java:1641)
@gayanW
Copy link
Collaborator Author

gayanW commented Aug 2, 2018

Please see the made changes.

@cyrille-artho cyrille-artho merged commit a95fd23 into javapathfinder:java-10 Aug 2, 2018
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