Skip to content

Commit 9a2592f

Browse files
committed
8374953: Add note on about implicit state when comparing TypeMirrors
Reviewed-by: attila, vromero, jlahoda
1 parent d433ce5 commit 9a2592f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/java.compiler/share/classes/javax/lang/model/type/TypeMirror.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -120,6 +120,15 @@ public interface TypeMirror extends AnnotatedConstruct {
120120
* The results of {@code t1.equals(t2)} and
121121
* {@code Types.isSameType(t1, t2)} may differ.
122122
*
123+
* @apiNote The identity of a {@code TypeMirror} involves implicit
124+
* state not directly accessible from its methods, including state
125+
* about the presence of unrelated types. {@code TypeMirror}
126+
* objects created by different implementations of these
127+
* interfaces should <i>not</i> be expected to compare as equal
128+
* even if &quot;the same&quot; type is being modeled; this is
129+
* analogous to the inequality of {@code Class} objects for the
130+
* same class file loaded through different class loaders.
131+
*
123132
* @param obj the object to be compared with this type
124133
* @return {@code true} if the specified object is equal to this one
125134
*/

src/java.compiler/share/classes/javax/lang/model/util/Types.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -106,6 +106,15 @@ public interface Types {
106106
* {@code TypeMirror} objects can have different annotations and
107107
* still be considered the same.
108108
*
109+
* @apiNote The identity of a {@code TypeMirror} involves implicit
110+
* state not directly accessible from its methods, including state
111+
* about the presence of unrelated types. {@code TypeMirror}
112+
* objects created by different implementations of these
113+
* interfaces should <i>not</i> be expected to compare as equal
114+
* even if &quot;the same&quot; type is being modeled; this is
115+
* analogous to the inequality of {@code Class} objects for the
116+
* same class file loaded through different class loaders.
117+
*
109118
* @param t1 the first type
110119
* @param t2 the second type
111120
* @return {@code true} if and only if the two types are the same

0 commit comments

Comments
 (0)