Skip to content

Commit

Permalink
Correct code and refine example
Browse files Browse the repository at this point in the history
  • Loading branch information
Ao-senXiong committed Jan 8, 2025
1 parent b0ed675 commit 5cc6842
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ public QualifierHierarchy createQualifierHierarchy() {

@Override
public ParameterizedExecutableType constructorFromUse(NewClassTree tree) {
boolean hasExplicitAnnos = getExplicitNewClassAnnos(tree).isEmpty();
boolean noExplicitAnnotations = getExplicitNewClassAnnos(tree).isEmpty();
ParameterizedExecutableType mType = super.constructorFromUse(tree);
AnnotatedExecutableType method = mType.executableType;
if (hasExplicitAnnos && method.getReturnType().hasAnnotation(RECEIVER_DEPENDENT_MUTABLE)) {
method.getReturnType().replaceAnnotation(MUTABLE);
if (noExplicitAnnotations
&& method.getReturnType().hasAnnotation(RECEIVER_DEPENDENT_MUTABLE)) {
method.getReturnType().replaceAnnotation(IMMUTABLE);
}
return mType;
}
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/pico-immutability/HashCodeSafetyExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class HashCodeSafetyExample {
public static void main(String[] args) {
A a = new A();
HashMap<A, String> m = new @Mutable HashMap<>();
Map<A, String> m = new @Mutable HashMap<>();
m.put(a, "hello");
System.out.println("HashCode before: " + a.hashCode());
// :: error: (illegal.field.write)
Expand Down

0 comments on commit 5cc6842

Please sign in to comment.