Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
cdc3a1c4
D
dragonwell8_langtools
项目概览
openanolis
/
dragonwell8_langtools
通知
0
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_langtools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cdc3a1c4
编写于
2月 18, 2013
作者:
V
vromero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6563143: javac should issue a warning for overriding equals without hashCode
Reviewed-by: jjg, mcimadamore
上级
468e329f
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
71 addition
and
8 deletion
+71
-8
src/share/classes/com/sun/tools/javac/code/Flags.java
src/share/classes/com/sun/tools/javac/code/Flags.java
+6
-1
src/share/classes/com/sun/tools/javac/code/Lint.java
src/share/classes/com/sun/tools/javac/code/Lint.java
+0
-3
src/share/classes/com/sun/tools/javac/comp/Attr.java
src/share/classes/com/sun/tools/javac/comp/Attr.java
+1
-0
src/share/classes/com/sun/tools/javac/comp/Check.java
src/share/classes/com/sun/tools/javac/comp/Check.java
+32
-0
src/share/classes/com/sun/tools/javac/comp/Resolve.java
src/share/classes/com/sun/tools/javac/comp/Resolve.java
+1
-0
src/share/classes/com/sun/tools/javac/resources/compiler.properties
...classes/com/sun/tools/javac/resources/compiler.properties
+5
-0
src/share/classes/com/sun/tools/sjavac/comp/Dependencies.java
...share/classes/com/sun/tools/sjavac/comp/Dependencies.java
+1
-4
test/tools/javac/6563143/OverridesEqualsButNotHashCodeTest.java
...ools/javac/6563143/OverridesEqualsButNotHashCodeTest.java
+22
-0
test/tools/javac/6563143/OverridesEqualsButNotHashCodeTest.out
...tools/javac/6563143/OverridesEqualsButNotHashCodeTest.out
+2
-0
test/tools/javac/diags/examples.not-yet.txt
test/tools/javac/diags/examples.not-yet.txt
+1
-0
未找到文件。
src/share/classes/com/sun/tools/javac/code/Flags.java
浏览文件 @
cdc3a1c4
...
...
@@ -258,7 +258,7 @@ public class Flags {
public
static
final
long
CLASH
=
1L
<<
42
;
/**
* Flag that marks either a default method or an interface containing default methods
* Flag that marks either a default method or an interface containing default methods
.
*/
public
static
final
long
DEFAULT
=
1L
<<
43
;
...
...
@@ -268,6 +268,11 @@ public class Flags {
*/
public
static
final
long
AUXILIARY
=
1L
<<
44
;
/**
* Flag that indicates that an override error has been detected by Check.
*/
public
static
final
long
BAD_OVERRIDE
=
1L
<<
45
;
/** Modifier masks.
*/
public
static
final
int
...
...
src/share/classes/com/sun/tools/javac/code/Lint.java
浏览文件 @
cdc3a1c4
...
...
@@ -26,10 +26,7 @@
package
com.sun.tools.javac.code
;
import
java.util.EnumSet
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.lang.model.element.Modifier
;
import
com.sun.tools.javac.code.Symbol.*
;
import
com.sun.tools.javac.util.Context
;
import
com.sun.tools.javac.util.List
;
...
...
src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
cdc3a1c4
...
...
@@ -3991,6 +3991,7 @@ public class Attr extends JCTree.Visitor {
attribClassBody
(
env
,
c
);
chk
.
checkDeprecatedAnnotation
(
env
.
tree
.
pos
(),
c
);
chk
.
checkClassOverrideEqualsAndHash
(
c
);
}
finally
{
env
.
info
.
returnResult
=
prevReturnRes
;
log
.
useSource
(
prev
);
...
...
src/share/classes/com/sun/tools/javac/comp/Check.java
浏览文件 @
cdc3a1c4
...
...
@@ -1588,6 +1588,7 @@ public class Check {
(
other
.
flags
()
&
STATIC
)
==
0
)
{
log
.
error
(
TreeInfo
.
diagnosticPositionFor
(
m
,
tree
),
"override.static"
,
cannotOverride
(
m
,
other
));
m
.
flags_field
|=
BAD_OVERRIDE
;
return
;
}
...
...
@@ -1599,6 +1600,7 @@ public class Check {
log
.
error
(
TreeInfo
.
diagnosticPositionFor
(
m
,
tree
),
"override.meth"
,
cannotOverride
(
m
,
other
),
asFlagSet
(
other
.
flags
()
&
(
FINAL
|
STATIC
)));
m
.
flags_field
|=
BAD_OVERRIDE
;
return
;
}
...
...
@@ -1615,6 +1617,7 @@ public class Check {
other
.
flags
()
==
0
?
Flag
.
PACKAGE
:
asFlagSet
(
other
.
flags
()
&
AccessFlags
));
m
.
flags_field
|=
BAD_OVERRIDE
;
return
;
}
...
...
@@ -1642,6 +1645,7 @@ public class Check {
"override.incompatible.ret"
,
cannotOverride
(
m
,
other
),
mtres
,
otres
);
m
.
flags_field
|=
BAD_OVERRIDE
;
return
;
}
}
else
if
(
overrideWarner
.
hasNonSilentLint
(
LintCategory
.
UNCHECKED
))
{
...
...
@@ -1661,6 +1665,7 @@ public class Check {
"override.meth.doesnt.throw"
,
cannotOverride
(
m
,
other
),
unhandledUnerased
.
head
);
m
.
flags_field
|=
BAD_OVERRIDE
;
return
;
}
else
if
(
unhandledUnerased
.
nonEmpty
())
{
...
...
@@ -1956,6 +1961,33 @@ public class Check {
}
}
public
void
checkClassOverrideEqualsAndHash
(
ClassSymbol
someClass
)
{
if
(
lint
.
isEnabled
(
LintCategory
.
OVERRIDES
))
{
boolean
hasEquals
=
false
;
boolean
hasHashCode
=
false
;
Scope
.
Entry
equalsAtObject
=
syms
.
objectType
.
tsym
.
members
().
lookup
(
names
.
equals
);
Scope
.
Entry
hashCodeAtObject
=
syms
.
objectType
.
tsym
.
members
().
lookup
(
names
.
hashCode
);
for
(
Symbol
s:
someClass
.
members
().
getElements
(
new
Filter
<
Symbol
>()
{
public
boolean
accepts
(
Symbol
s
)
{
return
s
.
kind
==
Kinds
.
MTH
&&
(
s
.
flags
()
&
BAD_OVERRIDE
)
==
0
;
}
}))
{
MethodSymbol
m
=
(
MethodSymbol
)
s
;
hasEquals
|=
m
.
name
.
equals
(
names
.
equals
)
&&
m
.
overrides
(
equalsAtObject
.
sym
,
someClass
,
types
,
false
);
hasHashCode
|=
m
.
name
.
equals
(
names
.
hashCode
)
&&
m
.
overrides
(
hashCodeAtObject
.
sym
,
someClass
,
types
,
false
);
}
if
(
hasEquals
&&
!
hasHashCode
)
{
log
.
warning
(
LintCategory
.
OVERRIDES
,
(
DiagnosticPosition
)
null
,
"override.equals.but.not.hashcode"
,
someClass
.
fullname
);
}
}
}
private
boolean
checkNameClash
(
ClassSymbol
origin
,
Symbol
s1
,
Symbol
s2
)
{
ClashFilter
cf
=
new
ClashFilter
(
origin
.
type
);
return
(
cf
.
accepts
(
s1
)
&&
...
...
src/share/classes/com/sun/tools/javac/comp/Resolve.java
浏览文件 @
cdc3a1c4
...
...
@@ -3606,6 +3606,7 @@ public class Resolve {
* while inapplicable candidates contain further details about the
* reason why the method has been considered inapplicable.
*/
@SuppressWarnings
(
"overrides"
)
class
Candidate
{
final
MethodResolutionPhase
step
;
...
...
src/share/classes/com/sun/tools/javac/resources/compiler.properties
浏览文件 @
cdc3a1c4
...
...
@@ -2065,6 +2065,11 @@ compiler.warn.override.unchecked.thrown=\
{0}
\n\
overridden method does not throw {1}
# 0: class name
compiler.warn.override.equals.but.not.hashcode
=
\
Class {0}
\n\
overrides method equals but does not overrides method hashCode from Object
## The following are all possible strings for the first argument ({0}) of the
## above strings.
# 0: symbol, 1: symbol, 2: symbol, 3: symbol
...
...
src/share/classes/com/sun/tools/sjavac/comp/Dependencies.java
浏览文件 @
cdc3a1c4
/*
* Copyright (c) 1999, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -113,9 +113,6 @@ public class Dependencies {
return
a
.
toString
().
compareTo
(
b
.
toString
());
}
public
boolean
equals
(
Object
obj
)
{
return
super
.
equals
(
obj
);
}
}
/**
...
...
test/tools/javac/6563143/OverridesEqualsButNotHashCodeTest.java
0 → 100644
浏览文件 @
cdc3a1c4
/*
* @test /nodynamiccopyright/
* @bug 6563143
* @summary javac should issue a warning for overriding equals without hashCode
* @compile/ref=OverridesEqualsButNotHashCodeTest.out -Xlint:overrides -XDrawDiagnostics OverridesEqualsButNotHashCodeTest.java
*/
@SuppressWarnings
(
"overrides"
)
public
class
OverridesEqualsButNotHashCodeTest
{
@Override
public
boolean
equals
(
Object
o
)
{
return
o
==
this
;
}
}
class
Other
{
@Override
public
boolean
equals
(
Object
o
)
{
return
o
==
this
;
}
}
test/tools/javac/6563143/OverridesEqualsButNotHashCodeTest.out
0 → 100644
浏览文件 @
cdc3a1c4
- compiler.warn.override.equals.but.not.hashcode: Other
1 warning
test/tools/javac/diags/examples.not-yet.txt
浏览文件 @
cdc3a1c4
...
...
@@ -110,4 +110,5 @@ compiler.warn.unchecked.cast.to.type # DEAD, replaced by comp
compiler.warn.unexpected.archive.file # Paths: zip file with unknown extn
compiler.warn.unknown.enum.constant # in bad class file
compiler.warn.unknown.enum.constant.reason # in bad class file
compiler.warn.override.equals.but.not.hashcode # when a class overrides equals but not hashCode method from Object
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录