On Tue, 25 May 2021 09:37:58 GMT, Patrick Concannon <pconcan...@openjdk.org> 
wrote:

> Hi,
> 
> Could someone please review my code for updating the code in the `java.io`, 
> `java.math`, and `java.text` packages to make use of the switch expressions?
> 
> Kind regards,
> Patrick

src/java.base/share/classes/java/io/ObjectInputStream.java line 1877:

> 1875:                 descriptor.checkInitialized();
> 1876:             }
> 1877:             default                 -> throw new 
> StreamCorruptedException(

What would you think of assigning descriptor with the value returned from 
evaluating the switch?

Either:

1) 

ObjectStreamClass descriptor = switch (tc) {
        case TC_NULL            -> (ObjectStreamClass) readNull();
        case TC_PROXYCLASSDESC  -> readProxyDesc(unshared);
        case TC_CLASSDESC       -> readNonProxyDesc(unshared);
        case TC_REFERENCE       -> readAndCheckHandle(unshared);
        default -> throw new StreamCorruptedException(String.format("invalid 
type code: %02X", tc));
    };
    return descriptor;
}

, where the body of TC_REFERENCE is enclosed in readAndCheckHandle,   OR

2) Simply 

  case TC_REFERENCE       -> {
        var d = (ObjectStreamClass)readHandle(unshared);
        // Should only reference initialized class descriptors
        d.checkInitialized();
        yield d; }

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

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

Reply via email to