<i18n dev> RFR: 8267670: Update java.io, java.math, and java.text to use switch expressions

Chris Hegarty chegar at openjdk.java.net
Tue May 25 12:34:55 UTC 2021


On Tue, 25 May 2021 09:37:58 GMT, Patrick Concannon <pconcannon at 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


More information about the i18n-dev mailing list