langtools/test/tools/javac/6563143/EqualsHashCodeWarningTest.java
author duke
Wed, 05 Jul 2017 18:59:39 +0200
changeset 18044 f1a01fb5f958
parent 16333 a6e1ded87200
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16301
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
     1
/*
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
     2
 * @test /nodynamiccopyright/
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
     3
 * @bug 6563143 8008436 8009138
16301
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
     4
 * @summary javac should issue a warning for overriding equals without hashCode
16320
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
     5
 * @summary javac should not issue a warning for overriding equals without hasCode
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
     6
 * @summary javac, equals-hashCode warning tuning
16320
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
     7
 * if hashCode has been overriden by a superclass
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
     8
 * @compile/ref=EqualsHashCodeWarningTest.out -Xlint:overrides -XDrawDiagnostics EqualsHashCodeWarningTest.java
16301
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
     9
 */
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    10
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    11
import java.util.Comparator;
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    12
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    13
public class EqualsHashCodeWarningTest {
16301
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    14
    @Override
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    15
    public boolean equals(Object o) {
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    16
        return o == this;
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    17
    }
16320
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    18
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    19
    @Override
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    20
    public int hashCode() {
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    21
        return 0;
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    22
    }
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    23
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    24
    public Comparator m() {
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    25
        return new Comparator() {
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    26
            @Override
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    27
            public boolean equals(Object o) {return true;}
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    28
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    29
            @Override
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    30
            public int compare(Object o1, Object o2) {
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    31
                return 0;
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    32
            }
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    33
        };
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    34
    }
16320
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    35
}
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    36
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    37
class SubClass extends EqualsHashCodeWarningTest {
16320
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    38
    @Override
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    39
    public boolean equals(Object o) {
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    40
        return true;
16320
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    41
    }
16301
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    42
}
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    43
16320
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    44
@SuppressWarnings("overrides")
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    45
class DontWarnMe {
16301
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    46
    @Override
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    47
    public boolean equals(Object o) {
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    48
        return true;
16301
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    49
    }
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    50
}
b6fd735ea78e 6563143: javac should issue a warning for overriding equals without hashCode
vromero
parents:
diff changeset
    51
16320
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    52
class DoWarnMe {
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    53
    @Override
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    54
    public boolean equals(Object o) {
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    55
        return o == this;
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    56
    }
92ba27b7aaf3 8008436: javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
vromero
parents: 16301
diff changeset
    57
}
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    58
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    59
abstract class IamAbstractGetMeOutOfHere {
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    60
    public boolean equals(Object o){return true;}
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    61
}
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    62
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    63
interface I {
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    64
    public boolean equals(Object o);
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    65
}
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    66
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    67
enum E {
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    68
    A, B
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    69
}
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    70
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16320
diff changeset
    71
@interface anno {}