Summary
Derby is written in java and the wonderful part is, it is thus expected to work across platforms without having the need to do any porting. Write once, run anywhere
But beware, there are constructors/methods/classes in Java that use default platform encoding and this can lead to non portable behavior across platforms. For e.g. new String(byte[]) uses default platform encoding to convert bytes to String.
Recently, when testing Derby on Z/OS, a number of issues were encountered because of usage of the encoding - unsafe methods in Derby code.
This page attempts to list the non portable methods in java that needs to be either avoided or investigated thoroughly as to why its use is required when writing Derby code. At the bare minimum, it is advised to please add a comment if a usage of such a method is absolutely required.
This list covers cases in String class and java.io package and is no means the complete list of all the non-portable methods in java. So please add/edit if you come across another non-portable method/class
There is existing bug DERBY-1256 that is a placeholder to remove/investigate the usage of all the non-portable methods in derby code. Please add information to this jira entry if you find any other occurences of non-portable methods usage.
Non-portable method |
Comments |
||
|
|
||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="41aadcaa-c531-48e5-b825-ffadb460157d"><ac:plain-text-body><![CDATA[ |
String(byte[]) |
|
]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="76e1a06d-68a1-41cd-99bb-356a2b6c252f"><ac:plain-text-body><![CDATA[ |
String(byte[],int,int) |
|
]]></ac:plain-text-body></ac:structured-macro> |
String.getBytes() |
|
||
ByteArrayOutputStream.toString() |
|
||
ByteArrayOutputStream.toString(int hibyte) |
Deprecated |
||
DataInputStream.readLine() |
also deprecated |
||
File.toURL() |
system dependent |
||
File.toURI() |
system dependent |
||
InputStreamReader(InputStream) |
Create an InputStreamReader that uses the default charset. |
||
deprecated, This class incorrectly assumes that bytes adequately represent char |
|||
LineNumberReader.readLine() |
unclear, but it seems like readLine() can cause problems on different platforms. Read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed. |
||
ObjectInputStream.readLine() |
|
||
Create an OutputStreamWriter that uses the default character encoding. |
|||
OutputStreamWriter.readLine() |
|
||
All characters printed by a PrintStream are converted into bytes using the platform's default character encoding |
|||
printf(float f)Print a floating-point number. The string produced by String.valueOf(float) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method. |
|||
RandomAccessFile.readLine() |
This method does not support the full Unicode character set. |
||
StringBufferInputStream(deprecated) |
This class does not properly convert characters into bytes |
Testing
To add tests with different default encoding, please look at encodingTests suite in the Derby test harness.
Jira issues
Status of Jira entries related to usage of non-encoding safe methods.
Jira Entry |
Comments |
|
|
Open,generic jira to remove/investigate usage of all encoding-unsafe and non portable methods in Derby |
|
Fixed |
|
Fixed |
|
Fixed |
|
Fixed |
|
Fixed |
|
Fixed |
|
Fixed |
|
Fixed |