RFR: 8265418: Clean-up redundant null-checks of Class.getPackageName()

Peter Levart plevart at openjdk.java.net
Tue Apr 27 13:53:40 UTC 2021

On Tue, 27 Apr 2021 09:17:43 GMT, Сергей Цыпанов <github.com+10835776+stsypanov at openjdk.org> wrote:

> > Also be careful not to return a string which
> > is not interned (which would happen if you did what you are proposing
> > above).
> Ok, I'm probably missing something, but when we move `String.intern()` call to `this.packageName = pn.intern();` there is no case when non-interned String is returned: there's only one assignment to the field `packageName` and the value assigned is always interned, right?

I see:

    return pn;
...in code. The local var is returned. As said, string constants are already interned. Calling .intern() on them will mean unnecessary overhead.


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

More information about the core-libs-dev mailing list