AvoidNonPortableMethods

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

String(byte[])

String(byte[],int,int)

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.

LineNumberInputStream

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()

OutputStreamWriter()

Create an OutputStreamWriter that uses the default character encoding.

OutputStreamWriter.readLine()

PrintStream

All characters printed by a PrintStream are converted into bytes using the platform's default character encoding

PrintWriter

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

[WWW] DERBY-1256

Open,generic jira to remove/investigate usage of all encoding-unsafe and non portable methods in Derby

[WWW] DERBY-900

Fixed

[WWW] DERBY-901

Fixed

[WWW] DERBY-902

Fixed

[WWW] DERBY-903

Fixed

[WWW] DERBY-972

Fixed

[WWW] DERBY-575

Fixed

[WWW] DERBY-1127

Fixed

[WWW] DERBY-877

Fixed

last edited 2006-05-18 00:00:17 by SunithaKambhampati