Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
beb1f215
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看板
提交
beb1f215
编写于
5月 13, 2014
作者:
V
vromero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8029102: Enhance compiler warnings for Lambda
Reviewed-by: briangoetz, jjg, jlahoda, ahgross
上级
a13ffe7b
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
503 addition
and
21 deletion
+503
-21
src/share/classes/com/sun/tools/javac/code/Symbol.java
src/share/classes/com/sun/tools/javac/code/Symbol.java
+1
-1
src/share/classes/com/sun/tools/javac/comp/Attr.java
src/share/classes/com/sun/tools/javac/comp/Attr.java
+47
-18
src/share/classes/com/sun/tools/javac/comp/AttrContext.java
src/share/classes/com/sun/tools/javac/comp/AttrContext.java
+6
-1
src/share/classes/com/sun/tools/javac/comp/Check.java
src/share/classes/com/sun/tools/javac/comp/Check.java
+40
-0
src/share/classes/com/sun/tools/javac/resources/compiler.properties
...classes/com/sun/tools/javac/resources/compiler.properties
+4
-0
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
+3
-1
test/tools/javac/T8029102/WarnSerializableLambdaTest.java
test/tools/javac/T8029102/WarnSerializableLambdaTest.java
+241
-0
test/tools/javac/T8029102/WarnSerializableLambdaTest.out
test/tools/javac/T8029102/WarnSerializableLambdaTest.out
+57
-0
test/tools/javac/T8029102/WarnSerializableLambdaTestb.java
test/tools/javac/T8029102/WarnSerializableLambdaTestb.java
+56
-0
test/tools/javac/T8029102/WarnSerializableLambdaTestb.out
test/tools/javac/T8029102/WarnSerializableLambdaTestb.out
+7
-0
test/tools/javac/diags/examples/WarnSerializableLambda.java
test/tools/javac/diags/examples/WarnSerializableLambda.java
+41
-0
未找到文件。
src/share/classes/com/sun/tools/javac/code/Symbol.java
浏览文件 @
beb1f215
...
...
@@ -392,7 +392,7 @@ public abstract class Symbol extends AnnoConstruct implements Element {
/** A class is an inner class if it it has an enclosing instance class.
*/
public
boolean
isInner
()
{
return
type
.
getEnclosingType
().
hasTag
(
CLASS
);
return
kind
==
TYP
&&
type
.
getEnclosingType
().
hasTag
(
CLASS
);
}
/** An inner class has an outer instance if it is not an interface
...
...
src/share/classes/com/sun/tools/javac/comp/Attr.java
浏览文件 @
beb1f215
...
...
@@ -2143,6 +2143,11 @@ public class Attr extends JCTree.Visitor {
cdef
.
extending
=
clazz
;
}
if
(
resultInfo
.
checkContext
.
deferredAttrContext
().
mode
==
DeferredAttr
.
AttrMode
.
CHECK
&&
isSerializable
(
clazztype
))
{
localEnv
.
info
.
isSerializable
=
true
;
}
attribStat
(
cdef
,
localEnv
);
checkLambdaCandidate
(
tree
,
cdef
.
sym
,
clazztype
);
...
...
@@ -2298,6 +2303,9 @@ public class Attr extends JCTree.Visitor {
resultInfo
.
checkContext
.
deferredAttrContext
().
mode
==
DeferredAttr
.
AttrMode
.
CHECK
;
try
{
Type
currentTarget
=
pt
();
if
(
needsRecovery
&&
isSerializable
(
currentTarget
))
{
localEnv
.
info
.
isSerializable
=
true
;
}
List
<
Type
>
explicitParamTypes
=
null
;
if
(
that
.
paramKind
==
JCLambda
.
ParameterKind
.
EXPLICIT
)
{
//attribute lambda parameters
...
...
@@ -2702,17 +2710,20 @@ public class Attr extends JCTree.Visitor {
typeargtypes
=
attribTypes
(
that
.
typeargs
,
localEnv
);
}
Type
target
;
Type
desc
;
if
(
pt
()
!=
Type
.
recoveryType
)
{
target
=
targetChecker
.
visit
(
pt
(),
that
);
desc
=
types
.
findDescriptorType
(
target
);
Type
currentTarget
=
pt
();
boolean
isTargetSerializable
=
resultInfo
.
checkContext
.
deferredAttrContext
().
mode
==
DeferredAttr
.
AttrMode
.
CHECK
&&
isSerializable
(
currentTarget
);
if
(
currentTarget
!=
Type
.
recoveryType
)
{
currentTarget
=
targetChecker
.
visit
(
currentTarget
,
that
);
desc
=
types
.
findDescriptorType
(
currentTarget
);
}
else
{
t
arget
=
Type
.
recoveryType
;
currentT
arget
=
Type
.
recoveryType
;
desc
=
fallbackDescriptorType
(
that
);
}
setFunctionalInfo
(
localEnv
,
that
,
pt
(),
desc
,
t
arget
,
resultInfo
.
checkContext
);
setFunctionalInfo
(
localEnv
,
that
,
pt
(),
desc
,
currentT
arget
,
resultInfo
.
checkContext
);
List
<
Type
>
argtypes
=
desc
.
getParameterTypes
();
Resolve
.
MethodCheck
referenceCheck
=
rs
.
resolveMethodCheck
;
...
...
@@ -2763,10 +2774,10 @@ public class Attr extends JCTree.Visitor {
JCDiagnostic
diag
=
diags
.
create
(
diagKind
,
log
.
currentSource
(),
that
,
"invalid.mref"
,
Kinds
.
kindName
(
that
.
getMode
()),
detailsDiag
);
if
(
targetError
&&
t
arget
==
Type
.
recoveryType
)
{
if
(
targetError
&&
currentT
arget
==
Type
.
recoveryType
)
{
//a target error doesn't make sense during recovery stage
//as we don't know what actual parameter types are
result
=
that
.
type
=
t
arget
;
result
=
that
.
type
=
currentT
arget
;
return
;
}
else
{
if
(
targetError
)
{
...
...
@@ -2774,7 +2785,7 @@ public class Attr extends JCTree.Visitor {
}
else
{
log
.
report
(
diag
);
}
result
=
that
.
type
=
types
.
createErrorType
(
t
arget
);
result
=
that
.
type
=
types
.
createErrorType
(
currentT
arget
);
return
;
}
}
...
...
@@ -2785,7 +2796,7 @@ public class Attr extends JCTree.Visitor {
if
(
desc
.
getReturnType
()
==
Type
.
recoveryType
)
{
// stop here
result
=
that
.
type
=
t
arget
;
result
=
that
.
type
=
currentT
arget
;
return
;
}
...
...
@@ -2803,7 +2814,7 @@ public class Attr extends JCTree.Visitor {
//static ref with class type-args
log
.
error
(
that
.
expr
.
pos
(),
"invalid.mref"
,
Kinds
.
kindName
(
that
.
getMode
()),
diags
.
fragment
(
"static.mref.with.targs"
));
result
=
that
.
type
=
types
.
createErrorType
(
t
arget
);
result
=
that
.
type
=
types
.
createErrorType
(
currentT
arget
);
return
;
}
...
...
@@ -2812,7 +2823,7 @@ public class Attr extends JCTree.Visitor {
//no static bound mrefs
log
.
error
(
that
.
expr
.
pos
(),
"invalid.mref"
,
Kinds
.
kindName
(
that
.
getMode
()),
diags
.
fragment
(
"static.bound.mref"
));
result
=
that
.
type
=
types
.
createErrorType
(
t
arget
);
result
=
that
.
type
=
types
.
createErrorType
(
currentT
arget
);
return
;
}
...
...
@@ -2820,6 +2831,10 @@ public class Attr extends JCTree.Visitor {
// Check that super-qualified symbols are not abstract (JLS)
rs
.
checkNonAbstract
(
that
.
pos
(),
that
.
sym
);
}
if
(
isTargetSerializable
)
{
chk
.
checkElemAccessFromSerializableLambda
(
that
);
}
}
ResultInfo
checkInfo
=
...
...
@@ -2851,9 +2866,9 @@ public class Attr extends JCTree.Visitor {
resultInfo
.
checkContext
.
deferredAttrContext
().
mode
==
DeferredAttr
.
AttrMode
.
SPECULATIVE
;
checkReferenceCompatible
(
that
,
desc
,
refType
,
resultInfo
.
checkContext
,
isSpeculativeRound
);
if
(!
isSpeculativeRound
)
{
checkAccessibleTypes
(
that
,
localEnv
,
resultInfo
.
checkContext
.
inferenceContext
(),
desc
,
t
arget
);
checkAccessibleTypes
(
that
,
localEnv
,
resultInfo
.
checkContext
.
inferenceContext
(),
desc
,
currentT
arget
);
}
result
=
check
(
that
,
t
arget
,
VAL
,
resultInfo
);
result
=
check
(
that
,
currentT
arget
,
VAL
,
resultInfo
);
}
catch
(
Types
.
FunctionDescriptorLookupError
ex
)
{
JCDiagnostic
cause
=
ex
.
getDiagnostic
();
resultInfo
.
checkContext
.
report
(
that
,
cause
);
...
...
@@ -3193,6 +3208,11 @@ public class Attr extends JCTree.Visitor {
while
(
env1
.
outer
!=
null
&&
!
rs
.
isAccessible
(
env
,
env1
.
enclClass
.
sym
.
type
,
sym
))
env1
=
env1
.
outer
;
}
if
(
env
.
info
.
isSerializable
)
{
chk
.
checkElemAccessFromSerializableLambda
(
tree
);
}
result
=
checkId
(
tree
,
env1
.
enclClass
.
sym
.
type
,
sym
,
env
,
resultInfo
);
}
...
...
@@ -3317,6 +3337,10 @@ public class Attr extends JCTree.Visitor {
}
}
if
(
env
.
info
.
isSerializable
)
{
chk
.
checkElemAccessFromSerializableLambda
(
tree
);
}
env
.
info
.
selectSuper
=
selectSuperPrev
;
result
=
checkId
(
tree
,
site
,
sym
,
env
,
resultInfo
);
}
...
...
@@ -4195,6 +4219,11 @@ public class Attr extends JCTree.Visitor {
((
c
.
flags_field
&
(
Flags
.
ENUM
|
Flags
.
COMPOUND
))
==
0
))
{
log
.
error
(
env
.
tree
.
pos
(),
"enum.types.not.extensible"
);
}
if
(
isSerializable
(
c
.
type
))
{
env
.
info
.
isSerializable
=
true
;
}
attribClassBody
(
env
,
c
);
chk
.
checkDeprecatedAnnotation
(
env
.
tree
.
pos
(),
c
);
...
...
@@ -4308,7 +4337,7 @@ public class Attr extends JCTree.Visitor {
// Check for proper use of serialVersionUID
if
(
env
.
info
.
lint
.
isEnabled
(
LintCategory
.
SERIAL
)
&&
isSerializable
(
c
)
&&
isSerializable
(
c
.
type
)
&&
(
c
.
flags
()
&
Flags
.
ENUM
)
==
0
&&
checkForSerial
(
c
))
{
checkSerialVersionUID
(
tree
,
c
);
...
...
@@ -4348,15 +4377,15 @@ public class Attr extends JCTree.Visitor {
return
null
;
}
/** check if a
class
is a subtype of Serializable, if that is available. */
private
boolean
isSerializable
(
ClassSymbol
c
)
{
/** check if a
type
is a subtype of Serializable, if that is available. */
boolean
isSerializable
(
Type
t
)
{
try
{
syms
.
serializableType
.
complete
();
}
catch
(
CompletionFailure
e
)
{
return
false
;
}
return
types
.
isSubtype
(
c
.
type
,
syms
.
serializableType
);
return
types
.
isSubtype
(
t
,
syms
.
serializableType
);
}
/** Check that an appropriate serialVersionUID member is defined. */
...
...
src/share/classes/com/sun/tools/javac/comp/AttrContext.java
浏览文件 @
beb1f215
/*
* Copyright (c) 1999, 201
2
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 201
4
, 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
...
...
@@ -54,6 +54,10 @@ public class AttrContext {
*/
boolean
selectSuper
=
false
;
/** Is the current target of lambda expression or method reference serializable?
*/
boolean
isSerializable
=
false
;
/** Are arguments to current function applications boxed into an array for varargs?
*/
Resolve
.
MethodResolutionPhase
pendingResolutionPhase
=
null
;
...
...
@@ -89,6 +93,7 @@ public class AttrContext {
info
.
enclVar
=
enclVar
;
info
.
returnResult
=
returnResult
;
info
.
defaultSuperCallSite
=
defaultSuperCallSite
;
info
.
isSerializable
=
isSerializable
;
return
info
;
}
...
...
src/share/classes/com/sun/tools/javac/comp/Check.java
浏览文件 @
beb1f215
...
...
@@ -82,6 +82,7 @@ public class Check {
private
final
TreeInfo
treeinfo
;
private
final
JavaFileManager
fileManager
;
private
final
Profile
profile
;
private
final
boolean
warnOnAccessToSensitiveMembers
;
// The set of lint options currently in effect. It is initialized
// from the context, and then is set/reset as needed by Attr as it
...
...
@@ -131,6 +132,7 @@ public class Check {
warnOnSyntheticConflicts
=
options
.
isSet
(
"warnOnSyntheticConflicts"
);
suppressAbortOnBadClassFile
=
options
.
isSet
(
"suppressAbortOnBadClassFile"
);
enableSunApiLintControl
=
options
.
isSet
(
"enableSunApiLintControl"
);
warnOnAccessToSensitiveMembers
=
options
.
isSet
(
"warnOnAccessToSensitiveMembers"
);
Target
target
=
Target
.
instance
(
context
);
syntheticNameChar
=
target
.
syntheticNameChar
();
...
...
@@ -2588,6 +2590,44 @@ public class Check {
}
}
void
checkElemAccessFromSerializableLambda
(
final
JCTree
tree
)
{
if
(
warnOnAccessToSensitiveMembers
)
{
Symbol
sym
=
TreeInfo
.
symbol
(
tree
);
if
((
sym
.
kind
&
(
VAR
|
MTH
))
==
0
)
{
return
;
}
if
(
sym
.
kind
==
VAR
)
{
if
((
sym
.
flags
()
&
PARAMETER
)
!=
0
||
sym
.
isLocal
()
||
sym
.
name
==
names
.
_this
||
sym
.
name
==
names
.
_super
)
{
return
;
}
}
if
(!
types
.
isSubtype
(
sym
.
owner
.
type
,
syms
.
serializableType
)
&&
isEffectivelyNonPublic
(
sym
))
{
log
.
warning
(
tree
.
pos
(),
"access.to.sensitive.member.from.serializable.element"
,
sym
);
}
}
}
private
boolean
isEffectivelyNonPublic
(
Symbol
sym
)
{
if
(
sym
.
packge
()
==
syms
.
rootPackage
)
{
return
false
;
}
while
(
sym
.
kind
!=
Kinds
.
PCK
)
{
if
((
sym
.
flags
()
&
PUBLIC
)
==
0
)
{
return
true
;
}
sym
=
sym
.
owner
;
}
return
false
;
}
/** Report a conflict between a user symbol and a synthetic symbol.
*/
private
void
syntheticError
(
DiagnosticPosition
pos
,
Symbol
sym
)
{
...
...
src/share/classes/com/sun/tools/javac/resources/compiler.properties
浏览文件 @
beb1f215
...
...
@@ -1617,6 +1617,10 @@ compiler.warn.diamond.redundant.args.1=\
compiler.warn.varargs.redundant.trustme.anno
=
\
Redundant {0} annotation. {1}
# 0: symbol
compiler.warn.access.to.sensitive.member.from.serializable.element
=
\
access to sensitive member {0} from serializable element can be publicly accessible to untrusted code
#####
## The following are tokens which are non-terminals in the language. They should
...
...
src/share/classes/com/sun/tools/javac/tree/TreeInfo.java
浏览文件 @
beb1f215
/*
* Copyright (c) 1999, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 201
4
, 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
...
...
@@ -831,6 +831,8 @@ public class TreeInfo {
return
symbol
(((
JCTypeApply
)
tree
).
clazz
);
case
ANNOTATED_TYPE:
return
symbol
(((
JCAnnotatedType
)
tree
).
underlyingType
);
case
REFERENCE:
return
((
JCMemberReference
)
tree
).
sym
;
default
:
return
null
;
}
...
...
test/tools/javac/T8029102/WarnSerializableLambdaTest.java
0 → 100644
浏览文件 @
beb1f215
/*
* @test /nodynamiccopyright/
* @bug 8029102
* @summary Enhance compiler warnings for Lambda
* Checks that the warning for accessing non public members of a class is
* fired correctly.
* @compile/fail/ref=WarnSerializableLambdaTest.out -XDrawDiagnostics -Werror -XDwarnOnAccessToSensitiveMembers WarnSerializableLambdaTest.java
*/
import
java.io.Serializable
;
public
class
WarnSerializableLambdaTest
{
void
warnLambda
()
throws
Exception
{
SAM
t3
=
(
SAM
&
Serializable
)
WarnSerializableLambdaTest:
:
packageClassMethod
;
SAM
t4
=
(
SAM
&
Serializable
)
WarnSerializableLambdaTest:
:
protectedClassMethod
;
SAM
t5
=
(
SAM
&
Serializable
)
WarnSerializableLambdaTest:
:
privateClassMethod
;
WarnSerializableLambdaTest
test
=
new
WarnSerializableLambdaTest
();
SAM
t6
=
(
SAM
&
Serializable
)
test:
:
packageInstanceMethod
;
SAM
t7
=
(
SAM
&
Serializable
)
test:
:
protectedInstanceMethod
;
SAM
t8
=
(
SAM
&
Serializable
)
test:
:
privateInstanceMethod
;
SAM
t9
=
(
SAM
&
Serializable
)
c
->
{
WarnSerializableLambdaTest
.
staticPackageField
=
""
;
WarnSerializableLambdaTest
.
staticProtectedField
=
""
;
WarnSerializableLambdaTest
.
staticPrivateField
=
""
;
packageField
=
""
;
protectedField
=
""
;
privateField
=
""
;
WarnSerializableLambdaTest
.
packageClassMethod
(
null
);
WarnSerializableLambdaTest
.
protectedClassMethod
(
null
);
WarnSerializableLambdaTest
.
privateClassMethod
(
null
);
packageInstanceMethod
(
null
);
protectedInstanceMethod
(
null
);
privateInstanceMethod
(
null
);
PrivateClass
.
effectivelyNonPublicStaticField
=
""
;
PrivateClass
.
effectivelyNonPublicClassMethod
();
PrivateClass
p
=
new
PrivateClass
();
p
.
effectivelyNonPublicInstanceField
=
""
;
p
.
effectivelyNonPublicInstanceMethod
();
return
null
;
};
}
private
void
warnAnoInnerClass
()
throws
Exception
{
new
SerializableDesc
()
{
public
void
m
(
Object
param
)
throws
Exception
{
WarnSerializableLambdaTest
.
staticPackageField
=
""
;
WarnSerializableLambdaTest
.
staticProtectedField
=
""
;
WarnSerializableLambdaTest
.
staticPrivateField
=
""
;
packageField
=
""
;
protectedField
=
""
;
privateField
=
""
;
WarnSerializableLambdaTest
.
packageClassMethod
(
null
);
WarnSerializableLambdaTest
.
protectedClassMethod
(
null
);
WarnSerializableLambdaTest
.
privateClassMethod
(
null
);
packageInstanceMethod
(
null
);
protectedInstanceMethod
(
null
);
privateInstanceMethod
(
null
);
PrivateClass
.
effectivelyNonPublicStaticField
=
""
;
PrivateClass
.
effectivelyNonPublicClassMethod
();
PrivateClass
p
=
new
PrivateClass
();
p
.
effectivelyNonPublicInstanceField
=
""
;
p
.
effectivelyNonPublicInstanceMethod
();
}
};
}
void
dontWarnLambda
()
throws
Exception
{
SAM
t1
=
(
SAM
&
Serializable
)
WarnSerializableLambdaTest:
:
publicClassMethod
;
WarnSerializableLambdaTest
test
=
new
WarnSerializableLambdaTest
();
SAM
t2
=
(
SAM
&
Serializable
)
test:
:
publicInstanceMethod
;
int
[]
buffer
=
{
0
};
SAM
t3
=
(
SAM
&
Serializable
)
param
->
{
Object
localVar
;
localVar
=
null
;
param
=
null
;
WarnSerializableLambdaTest
.
staticPublicField
=
""
;
publicField
=
""
;
WarnSerializableLambdaTest
.
publicClassMethod
(
null
);
publicInstanceMethod
(
null
);
PublicClass
.
effectivelyPublicStaticField
=
""
;
PublicClass
.
effectivelyPublicClassMethod
();
PublicClass
p
=
new
PublicClass
();
p
.
effectivelyPublicInstanceField
=
""
;
p
.
effectivelyPublicInstanceMethod
();
int
l
=
buffer
.
length
;
return
null
;
};
}
private
void
dontWarnAnoInnerClass
()
throws
Exception
{
final
int
[]
buffer
=
{
0
};
new
SerializableDesc
()
{
public
void
m
(
Object
param
)
throws
Exception
{
Object
localVar
;
localVar
=
null
;
param
=
null
;
WarnSerializableLambdaTest
.
staticPublicField
=
""
;
publicField
=
""
;
WarnSerializableLambdaTest
.
publicClassMethod
(
null
);
publicInstanceMethod
(
null
);
PublicClass
.
effectivelyPublicStaticField
=
""
;
PublicClass
.
effectivelyPublicClassMethod
();
PublicClass
p
=
new
PublicClass
();
p
.
effectivelyPublicInstanceField
=
""
;
p
.
effectivelyPublicInstanceMethod
();
int
l
=
buffer
.
length
;
}
};
}
enum
WarnEnum
{
A
{
public
void
m
()
throws
Exception
{
WarnSerializableLambdaTest
.
staticPackageField
=
""
;
WarnSerializableLambdaTest
.
staticProtectedField
=
""
;
WarnSerializableLambdaTest
.
staticPrivateField
=
""
;
WarnSerializableLambdaTest
test
=
new
WarnSerializableLambdaTest
();
test
.
packageField
=
""
;
test
.
protectedField
=
""
;
test
.
privateField
=
""
;
WarnSerializableLambdaTest
.
packageClassMethod
(
null
);
WarnSerializableLambdaTest
.
protectedClassMethod
(
null
);
WarnSerializableLambdaTest
.
privateClassMethod
(
null
);
test
.
packageInstanceMethod
(
null
);
test
.
protectedInstanceMethod
(
null
);
test
.
privateInstanceMethod
(
null
);
PrivateClass
.
effectivelyNonPublicStaticField
=
""
;
PrivateClass
.
effectivelyNonPublicClassMethod
();
PrivateClass
p
=
new
PrivateClass
();
p
.
effectivelyNonPublicInstanceField
=
""
;
p
.
effectivelyNonPublicInstanceMethod
();
}
};
public
void
m
()
throws
Exception
{}
}
static
String
staticPackageField
;
static
private
String
staticPrivateField
;
static
protected
String
staticProtectedField
;
static
public
String
staticPublicField
;
String
packageField
;
private
String
privateField
;
protected
String
protectedField
;
public
String
publicField
;
static
Object
packageClassMethod
(
String
s
)
{
return
null
;
}
static
private
Object
privateClassMethod
(
String
s
)
{
return
null
;
}
static
protected
Object
protectedClassMethod
(
String
s
)
{
return
null
;
}
static
public
Object
publicClassMethod
(
String
s
)
{
return
null
;
}
Object
packageInstanceMethod
(
String
s
)
{
return
null
;
}
protected
Object
protectedInstanceMethod
(
String
s
)
{
return
null
;
}
private
Object
privateInstanceMethod
(
String
s
)
{
return
null
;
}
public
Object
publicInstanceMethod
(
String
s
)
{
return
null
;
}
interface
SAM
{
Object
apply
(
String
s
)
throws
Exception
;
}
interface
SAM2
{
Object
apply
(
String
arg1
,
String
arg2
);
}
class
SerializableDesc
implements
Serializable
{
public
void
m
(
Object
param
)
throws
Exception
{}
}
static
private
class
PrivateClass
{
static
public
String
effectivelyNonPublicStaticField
;
public
String
effectivelyNonPublicInstanceField
;
static
public
void
effectivelyNonPublicClassMethod
()
{}
public
void
effectivelyNonPublicInstanceMethod
()
{}
}
static
public
class
PublicClass
{
static
public
String
effectivelyPublicStaticField
;
public
String
effectivelyPublicInstanceField
;
static
public
void
effectivelyPublicClassMethod
()
{}
public
void
effectivelyPublicInstanceMethod
()
{}
}
}
test/tools/javac/T8029102/WarnSerializableLambdaTest.out
0 → 100644
浏览文件 @
beb1f215
WarnSerializableLambdaTest.java:15:38: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:16:38: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:17:38: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:20:38: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:21:38: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:22:38: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:26:39: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPackageField
WarnSerializableLambdaTest.java:27:39: compiler.warn.access.to.sensitive.member.from.serializable.element: staticProtectedField
WarnSerializableLambdaTest.java:28:39: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPrivateField
WarnSerializableLambdaTest.java:30:13: compiler.warn.access.to.sensitive.member.from.serializable.element: packageField
WarnSerializableLambdaTest.java:31:13: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedField
WarnSerializableLambdaTest.java:32:13: compiler.warn.access.to.sensitive.member.from.serializable.element: privateField
WarnSerializableLambdaTest.java:34:39: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:35:39: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:36:39: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:38:13: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:39:13: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:40:13: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:42:25: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicStaticField
WarnSerializableLambdaTest.java:43:25: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicClassMethod()
WarnSerializableLambdaTest.java:46:14: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceField
WarnSerializableLambdaTest.java:47:14: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceMethod()
WarnSerializableLambdaTest.java:56:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPackageField
WarnSerializableLambdaTest.java:57:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticProtectedField
WarnSerializableLambdaTest.java:58:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPrivateField
WarnSerializableLambdaTest.java:60:17: compiler.warn.access.to.sensitive.member.from.serializable.element: packageField
WarnSerializableLambdaTest.java:61:17: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedField
WarnSerializableLambdaTest.java:62:17: compiler.warn.access.to.sensitive.member.from.serializable.element: privateField
WarnSerializableLambdaTest.java:64:43: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:65:43: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:66:43: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:68:17: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:69:17: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:70:17: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:72:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicStaticField
WarnSerializableLambdaTest.java:73:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicClassMethod()
WarnSerializableLambdaTest.java:76:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceField
WarnSerializableLambdaTest.java:77:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceMethod()
WarnSerializableLambdaTest.java:141:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPackageField
WarnSerializableLambdaTest.java:142:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticProtectedField
WarnSerializableLambdaTest.java:143:43: compiler.warn.access.to.sensitive.member.from.serializable.element: staticPrivateField
WarnSerializableLambdaTest.java:148:21: compiler.warn.access.to.sensitive.member.from.serializable.element: packageField
WarnSerializableLambdaTest.java:149:21: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedField
WarnSerializableLambdaTest.java:150:21: compiler.warn.access.to.sensitive.member.from.serializable.element: privateField
WarnSerializableLambdaTest.java:152:43: compiler.warn.access.to.sensitive.member.from.serializable.element: packageClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:153:43: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:154:43: compiler.warn.access.to.sensitive.member.from.serializable.element: privateClassMethod(java.lang.String)
WarnSerializableLambdaTest.java:156:21: compiler.warn.access.to.sensitive.member.from.serializable.element: packageInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:157:21: compiler.warn.access.to.sensitive.member.from.serializable.element: protectedInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:158:21: compiler.warn.access.to.sensitive.member.from.serializable.element: privateInstanceMethod(java.lang.String)
WarnSerializableLambdaTest.java:160:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicStaticField
WarnSerializableLambdaTest.java:161:29: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicClassMethod()
WarnSerializableLambdaTest.java:164:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceField
WarnSerializableLambdaTest.java:165:18: compiler.warn.access.to.sensitive.member.from.serializable.element: effectivelyNonPublicInstanceMethod()
- compiler.err.warnings.and.werror
1 error
54 warnings
test/tools/javac/T8029102/WarnSerializableLambdaTestb.java
0 → 100644
浏览文件 @
beb1f215
/*
* @test /nodynamiccopyright/
* @bug 8029102
* @summary Enhance compiler warnings for Lambda
* Checks that the warning for accessing non public members of a class is
* fired correctly.
* @compile/fail/ref=WarnSerializableLambdaTestb.out -XDrawDiagnostics -Werror -XDwarnOnAccessToSensitiveMembers WarnSerializableLambdaTestb.java
*/
import
java.io.Serializable
;
public
class
WarnSerializableLambdaTestb
{
public
void
foo
(
Secret1
secret
)
{
Object
o
=
(
Runnable
&
java
.
io
.
Serializable
)
()
->
{
secret
.
test
();
};
}
public
void
bar
(
Secret2
secret
)
{
Object
o
=
(
Runnable
&
java
.
io
.
Serializable
)
()
->
{
secret
.
test
();
};
}
private
class
Secret1
{
public
void
test
()
{}
}
static
private
class
Secret2
{
public
void
test
()
{}
}
class
TestInner
{
private
int
j
=
0
;
void
m
()
{
Serializable
s
=
new
Serializable
()
{
int
i
;
void
m
()
{
i
=
0
;
// don't warn
System
.
out
.
println
(
j
);
//warn
}
};
}
}
class
TestInner2
{
class
W
implements
Serializable
{
public
int
p
=
0
;
class
I
{
public
int
r
=
0
;
class
K
implements
Serializable
{
void
m
()
{
p
=
1
;
// don't warn owner is serializable
r
=
2
;
// warn owner is not serializable
}
}
}
}
}
}
test/tools/javac/T8029102/WarnSerializableLambdaTestb.out
0 → 100644
浏览文件 @
beb1f215
WarnSerializableLambdaTestb.java:14:69: compiler.warn.access.to.sensitive.member.from.serializable.element: test()
WarnSerializableLambdaTestb.java:18:69: compiler.warn.access.to.sensitive.member.from.serializable.element: test()
WarnSerializableLambdaTestb.java:36:40: compiler.warn.access.to.sensitive.member.from.serializable.element: j
WarnSerializableLambdaTestb.java:50:25: compiler.warn.access.to.sensitive.member.from.serializable.element: r
- compiler.err.warnings.and.werror
1 error
4 warnings
test/tools/javac/diags/examples/WarnSerializableLambda.java
0 → 100644
浏览文件 @
beb1f215
/*
* Copyright (c) 2014, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// key: compiler.warn.access.to.sensitive.member.from.serializable.element
// options: -XDwarnOnAccessToSensitiveMembers
import
java.io.Serializable
;
public
class
WarnSerializableLambda
{
interface
SAM
{
void
apply
(
String
s
);
}
private
void
m1
()
{
SAM
s
=
(
SAM
&
Serializable
)
c
->
{
packageField
=
""
;
};
}
String
packageField
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录