RFR: 8254234 - Add test library stream object builder

Roger Riggs rriggs at openjdk.java.net
Thu Oct 8 13:48:47 UTC 2020


On Thu, 8 Oct 2020 12:38:42 GMT, Chris Hegarty <chegar at openjdk.org> wrote:

> It is useful to have a test library facility for building stream objects, suitable for deserialization testing. We
> already have a partial implementation in one of the record serialization tests, move it to the test library for more
> general use. The implementation remains partial, but can be expanded as and when needed.

Changes requested by rriggs (Reviewer).

test/lib/jdk/test/lib/serial/SerialObjectBuilder.java line 93:

> 91:     }
> 92:
> 93:     private static int getPrimitiveSignature(Class<?> cl) {

The new java.lang.constant.TypeDescriptor will provide the primitive type from the Class.
Class implements TypeDescriptor including descriptorString.

This method can be replaced with clazz.descriptorString().

test/lib/jdk/test/lib/serial/SerialObjectBuilder.java line 140:

> 138:             Class<?> cl = entry.getKey().type();
> 139:             assert !cl.isPrimitive();
> 140:             // obj_typecode

Try replacing 141-150 with cl.descriptorString(). It looks like it will do all the encoding of the class.

test/lib/jdk/test/lib/serial/SerialObjectBuilder.java line 106:

> 104:
> 105:     private static void writeUTF(DataOutputStream out, String str) throws IOException {
> 106:         int utflen = str.length(); // assume ASCII

Add an assert to confirm its ASCII, or update the code to correctly estimate the number of bytes.
Possibly by using DOS to write to a temporary BAOS.

-------------

PR: https://git.openjdk.java.net/jdk/pull/561


More information about the core-libs-dev mailing list