From 40d623e676daff9f60ad6ffa6c723a7640eece04 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Wed, 21 Dec 2016 13:46:33 -0700 Subject: [PATCH] Tighter equals/hashCode method checking. Test: false-positive no longer triggered Bug: 32721082 Change-Id: I49b6225a7282d0bb84b0dfb4cabe56e9f68186a9 --- tools/apilint/apilint.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/apilint/apilint.py b/tools/apilint/apilint.py index 48a1330063c48..3fedea2cc08ad 100644 --- a/tools/apilint/apilint.py +++ b/tools/apilint/apilint.py @@ -403,9 +403,12 @@ def verify_extras(clazz): def verify_equals(clazz): """Verify that equals() and hashCode() must be overridden together.""" - methods = [ m.name for m in clazz.methods ] - eq = "equals" in methods - hc = "hashCode" in methods + eq = False + hc = False + for m in clazz.methods: + if " static " in m.raw: continue + if "boolean equals(java.lang.Object)" in m.raw: eq = True + if "int hashCode()" in m.raw: hc = True if eq != hc: error(clazz, None, "M8", "Must override both equals and hashCode; missing one")