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

Refactor String related classes and methods to comply with JEP 254 #133

Merged
merged 5 commits into from
Aug 1, 2018

Conversation

gayanW
Copy link
Collaborator

@gayanW gayanW commented Jul 31, 2018

This fixes the issues #127 and #132 which is about CastException that is being thrown due to String#value field returning a char array and sometimes a byte array. String data is always stored as byte[] array in the heap, hence it should always return a byte array. So the problem is with the way how JPF's heap implementation create String elements.

  • This sets String#value field as a byte[] instead of char[], when constructing ElementInfo(s) for String references in gov.nasa.jpf.vm.GenericHeap.

  • Deprecates ElementInfo.getStringChars and introduces the replacement method ElementInfo.getStringBytes

  • Fixes the occurrences where value field is being cast to a CharArrayFields

  • Delete JPF_java_lang_StringBuffer and JPF_java_lang_StringBuilder

    • Current implementations of JPF_java_lang_StringBuffer, and JPF_java_lang_StringBuilder is highly obsolete as the value field now being a byte[] instead of char[], and having a coder which specifies the encoding. Also, we are not able to use StringUTF16, StringLatin1 helper classes to help us with encoding and decoding since they are being package-private. Neither StringBuffer nor StringBuilder has any native methods. So it should be safe to remove these two.

@gayanW gayanW force-pushed the java-10_127_132 branch from 3734bcf to cef1b24 Compare July 31, 2018 12:45
gayanW added 5 commits July 31, 2018 18:16
String#value field should be set as a byte[] instead of char[], when
constructing ElementInfo(s) for String references in
gov.nasa.jpf.vm.GenericHeap.
This deprecates ElementInfo.getStringChars. Because String#value field
should now return a byte array instead of a char array.
ElementInfo.getStringBytes should be used instead.
Most methods in JPF_java_lang_String fail as the `value` field have
changed from char[] to a byte[] since JEP 254.

Instead of retrieving the value field, and performing operations on that
value field to return a result (which is now complex as the value field
now being a byte[] and and having a coder which specifies the different
encoding), we turn JPF String object into a VM String object using
MJIEnv.getStringObject and then delegates the method call to that VM
object.
…sString

String#value field can only be cast to ByteArrayFields as the value
field of String is a byte[] instead of char[]
Current implementations of JPF_java_lang_StringBuffer, and
JPF_java_lang_StringBuilder is highly obsolete as the value field now
being a byte[] instead of char[], and having a coder which specifies the
encoding. Also we are not able to use StringUTF16, StringLatin1 helper
classes to help us with encoding and decoding since they are being
package-private.

Neither StringBuffer nor StringBuilder have any native methods. So it
should be safe to remove these two.
@gayanW gayanW force-pushed the java-10_127_132 branch from cef1b24 to e655058 Compare July 31, 2018 12:47
@cyrille-artho cyrille-artho merged commit 03bc696 into javapathfinder:java-10 Aug 1, 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