latest changes in java.lang.Class

Andrew Luo andrewluotechnologies at outlook.com
Sun Dec 30 12:16:32 UTC 2018


Stream.of should not be used with null.

https://docs.oracle.com/javase/9/docs/api/java/util/stream/Stream.html#of-T-

I think you'd be right if it were Stream.ofNullable, and there does appear to be a bug in that code (never appended to sb) - thanks for pointing that out...

Thanks,

-Andrew

-----Original Message-----
From: core-libs-dev <core-libs-dev-bounces at openjdk.java.net> On Behalf Of ?????? ???????
Sent: Saturday, December 29, 2018 11:23 PM
To: core-libs-dev <core-libs-dev at openjdk.java.net>
Subject: latest changes in java.lang.Class

Hi,

looking into Class::methodToString I've found some changes done into it recently in JDK 11 repository.

Currently the method looks like this:

private String methodToString(String name, Class<?>[] argTypes) {
    StringBuilder sb = new StringBuilder();
    sb.append(getName() + "." + name + "(");
    if (argTypes != null) {
        Stream.of(argTypes).map(c -> {return (c == null) ? "null" : c.getName();}).
            collect(Collectors.joining(","));
    }
    sb.append(")");
    return sb.toString();
}

Here result of Stream.collect() is ignored, i. e. even when condition argTypes != null is true nothing is appended to sb.
It seems in this case we either don’t need this `if` branch or need to append to sb.

Am I missing something?

Kind regards,
Sergey Tsypanov


More information about the core-libs-dev mailing list