G Custom SigTest Tool Example

This appendix gives an example of creating a custom tool based on the SigTest tool and its APIs. The example tool checks two implementations of a set of Java classes for serialization compatibility. You can create similar tools based on this example.

This appendix contains the following topics:

G.1 Overview

The serialization tool is an example of using the SigTest APIs to create a new kind of tool. The serialization tool verifies that two implementations of one set of classes can successfully serialize and deserialize instances of each other. For a description of serialization, see http://docs.oracle.com/javase/7/docs/technotes/guides/serialization/index.html.

G.2 Usage

The serialization tool has two commands and is run much like the base SigTest tool.

Setup command:
$ java com.sun.tdk.sertest.SerSetup [options]
Test command:
$ java com.sun.tdk.sertest.SerTest [options]

Be certain that sigtestdev.jar and sertest.jar are in the classpath. Most SigTest tool options are valid for the serialization tool.

The serialization tool differs from the base SigTest tool in the following ways:

  • Only java.io.Serializable classes are taken (except enums).

  • For all classes, only non-transient and non-static fields are tracked. Also serialVersionUID is required and its value is tracked.

  • Any serializable class must have a serialVersionUID.

  • Because of reflection limitations, access to class members via reflection is not supported, and the test command is always static regardless of the -static option.

  • The setup command always generates a -nonclosed signature file.

  • Signature files generated by this tool's setup command are incompatible with, and must not be used by, the base SigTest tool or any other custom tool derived from it. Conversely, signature files generated by other tools must not be used with the serialization tool.

G.3 Implementation

The serialization tool is implemented in the com.sun.tdk.sertest package in SigTest-Directory/examples/sertest/. There are three classes:

SerSetup

Main class for setup command

SerTest

Main class for test command

SerUtil

Common code for setup and test commands

For implementation details, see the Javadoc in the SigTest-Directory/javadoc/ directory.