RFR: 8263358: Update java.lang to use instanceof pattern variable [v5]

Mandy Chung mchung at openjdk.java.net
Tue Mar 16 17:28:10 UTC 2021


On Tue, 16 Mar 2021 11:13:50 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/StackTraceElement.java line 413:
>> 
>>> 411:                 && Objects.equals(moduleName, e.moduleName)
>>> 412:                 && Objects.equals(moduleVersion, e.moduleVersion)
>>> 413:                 && e.declaringClass.equals(declaringClass)
>> 
>> testing the declaring class and the line number should be done first given they are primitive values, it will be a little more efficient if two StackTraceElement are not equals and one is using non interned String.
>>   return (obj instanceof StackTraceElement e)
>>      && e.lineNumber == lineNumber
>>      && e.declaringClass == declaringClass
>>      && ...
>
> Hi Rémi,
> There seems to be a deeper issue here - Patrick pointed that out to me - the specification of equals above speaks of comparing class names where the actual implementation compares classes. Maybe the specification should be updated - but that would be better done in a separate issue with CSR etc... Maybe we can do the optimization you suggest at the same time?

`declaringClass` is a string representing the class name (not the `Class` object).   The variable name indeed causes confusion.

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

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


More information about the core-libs-dev mailing list