Skip to content

Commit 89882f9

Browse files
committed
squash: use Object.equals for comparing parsers and document the implications for parsers defined by lambdas
1 parent 2538c41 commit 89882f9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/annotation/AbstractAnnotated.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
package jdk.vm.ci.meta.annotation;
2424

25-
import java.util.Objects;
2625
import java.util.function.Function;
2726

2827
/**
@@ -56,7 +55,7 @@ public <T> T getDeclaredAnnotationInfo(Function<AnnotationsInfo, T> parser) {
5655
return (T) getRawDeclaredAnnotationInfo();
5756
}
5857
ParsedDeclaredAnnotationsCacheEntry<?> cache = parsedDeclaredAnnotationsCache;
59-
if (cache == null || cache.parser != Objects.requireNonNull(parser)) {
58+
if (cache == null || !parser.equals(cache.parser)) {
6059
AnnotationsInfo info = getRawDeclaredAnnotationInfo();
6160
cache = new ParsedDeclaredAnnotationsCacheEntry<>(parser, parser.apply(info));
6261
parsedDeclaredAnnotationsCache = cache;

src/jdk.internal.vm.ci/share/classes/jdk/vm/ci/meta/annotation/Annotated.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,23 @@ public interface Annotated {
3838
* parser function to it and returns the result.
3939
* <p>
4040
* The result of the last call to this method is cached if {@code parser != null}.
41-
* That is, if the same parser object is used again without any intervening calls with a different
42-
* parser, the same result object will be returned.
41+
* That is, if an {@linkplain Object#equals(Object) equivalent} parser object is
42+
* used again without any intervening calls with a different parser, the same
43+
* result object will be returned.
44+
* <p>
45+
* Note: Since lambda objects implement {@link Object#equals(Object)} with identity,
46+
* if {@code parser} is a lambda object, it should be a singleton in a final
47+
* static field. There is no guarantee about the identity of the result of a
48+
* lambda expression (JLS {@jls 15.27.4}).
4349
*
4450
* @param <T> the type of the result produced by the parser function
4551
* @param parser a function that takes the declared annotation information and
4652
* produces a result of type T. If {@code null}, then the
4753
* AnnotationsInfo value that would have been parsed is returned and
4854
* the cache is not updated.
4955
* @return the result of applying the parser function to the declared annotation
50-
* information, potentially retrieved from cache if the same parser
51-
* object was previously used
56+
* information, potentially retrieved from cache if the identical parser object
57+
* was previously used
5258
*/
5359
<T> T getDeclaredAnnotationInfo(Function<AnnotationsInfo, T> parser);
5460

0 commit comments

Comments
 (0)