Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
1098e2b6
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看板
提交
1098e2b6
编写于
8月 16, 2013
作者:
V
vromero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8022053: javac generates unverifiable initializer for nested subclass of local class
Reviewed-by: jjg, mcimadamore
上级
d50fd747
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
110 addition
and
15 deletion
+110
-15
src/share/classes/com/sun/tools/javac/comp/Lower.java
src/share/classes/com/sun/tools/javac/comp/Lower.java
+37
-15
test/tools/javac/T8022053/UnverifiableInitForNestedLocalClassTest.java
...vac/T8022053/UnverifiableInitForNestedLocalClassTest.java
+73
-0
未找到文件。
src/share/classes/com/sun/tools/javac/comp/Lower.java
浏览文件 @
1098e2b6
...
...
@@ -356,22 +356,44 @@ public class Lower extends TreeTranslator {
}
}
ClassSymbol
ownerToCopyFreeVarsFrom
(
ClassSymbol
c
)
{
if
(!
c
.
isLocal
())
{
return
null
;
}
Symbol
currentOwner
=
c
.
owner
;
while
((
currentOwner
.
owner
.
kind
&
TYP
)
!=
0
&&
currentOwner
.
isLocal
())
{
currentOwner
=
currentOwner
.
owner
;
}
if
((
currentOwner
.
owner
.
kind
&
(
VAR
|
MTH
))
!=
0
&&
c
.
isSubClass
(
currentOwner
,
types
))
{
return
(
ClassSymbol
)
currentOwner
;
}
return
null
;
}
/** Return the variables accessed from within a local class, which
* are declared in the local class' owner.
* (in reverse order of first access).
*/
List
<
VarSymbol
>
freevars
(
ClassSymbol
c
)
{
List
<
VarSymbol
>
fvs
=
freevarCache
.
get
(
c
);
if
(
fvs
!=
null
)
{
return
fvs
;
}
if
((
c
.
owner
.
kind
&
(
VAR
|
MTH
))
!=
0
)
{
List
<
VarSymbol
>
fvs
=
freevarCache
.
get
(
c
);
if
(
fvs
==
null
)
{
FreeVarCollector
collector
=
new
FreeVarCollector
(
c
);
collector
.
scan
(
classDef
(
c
));
fvs
=
collector
.
fvs
;
freevarCache
.
put
(
c
,
fvs
);
}
FreeVarCollector
collector
=
new
FreeVarCollector
(
c
);
collector
.
scan
(
classDef
(
c
));
fvs
=
collector
.
fvs
;
freevarCache
.
put
(
c
,
fvs
);
return
fvs
;
}
else
{
return
List
.
nil
();
ClassSymbol
owner
=
ownerToCopyFreeVarsFrom
(
c
);
if
(
owner
!=
null
)
{
fvs
=
freevarCache
.
get
(
owner
);
freevarCache
.
put
(
c
,
fvs
);
return
fvs
;
}
else
{
return
List
.
nil
();
}
}
}
...
...
@@ -1046,7 +1068,7 @@ public class Lower extends TreeTranslator {
boolean
needsPrivateAccess
(
Symbol
sym
)
{
if
((
sym
.
flags
()
&
PRIVATE
)
==
0
||
sym
.
owner
==
currentClass
)
{
return
false
;
}
else
if
(
sym
.
name
==
names
.
init
&&
(
sym
.
owner
.
owner
.
kind
&
(
VAR
|
MTH
))
!=
0
)
{
}
else
if
(
sym
.
name
==
names
.
init
&&
sym
.
owner
.
isLocal
()
)
{
// private constructor in local class: relax protection
sym
.
flags_field
&=
~
PRIVATE
;
return
false
;
...
...
@@ -2448,6 +2470,7 @@ public class Lower extends TreeTranslator {
tree
.
name
=
Convert
.
shortName
(
currentClass
.
flatName
());
// Add this$n and free variables proxy definitions to class.
for
(
List
<
JCVariableDecl
>
l
=
fvdefs
;
l
.
nonEmpty
();
l
=
l
.
tail
)
{
tree
.
defs
=
tree
.
defs
.
prepend
(
l
.
head
);
enterSynthetic
(
tree
.
pos
(),
l
.
head
.
sym
,
currentClass
.
members
());
...
...
@@ -2670,8 +2693,7 @@ public class Lower extends TreeTranslator {
//where
private
void
visitMethodDefInternal
(
JCMethodDecl
tree
)
{
if
(
tree
.
name
==
names
.
init
&&
(
currentClass
.
isInner
()
||
(
currentClass
.
owner
.
kind
&
(
VAR
|
MTH
))
!=
0
))
{
(
currentClass
.
isInner
()
||
currentClass
.
isLocal
()))
{
// We are seeing a constructor of an inner class.
MethodSymbol
m
=
tree
.
sym
;
...
...
@@ -2818,7 +2840,7 @@ public class Lower extends TreeTranslator {
// If created class is local, add free variables after
// explicit constructor arguments.
if
(
(
c
.
owner
.
kind
&
(
VAR
|
MTH
))
!=
0
)
{
if
(
c
.
isLocal
()
)
{
tree
.
args
=
tree
.
args
.
appendList
(
loadFreevars
(
tree
.
pos
(),
freevars
(
c
)));
}
...
...
@@ -2837,7 +2859,7 @@ public class Lower extends TreeTranslator {
if
(
tree
.
encl
!=
null
)
{
thisArg
=
attr
.
makeNullCheck
(
translate
(
tree
.
encl
));
thisArg
.
type
=
tree
.
encl
.
type
;
}
else
if
(
(
c
.
owner
.
kind
&
(
MTH
|
VAR
))
!=
0
)
{
}
else
if
(
c
.
isLocal
()
)
{
// local class
thisArg
=
makeThis
(
tree
.
pos
(),
c
.
type
.
getEnclosingType
().
tsym
);
}
else
{
...
...
@@ -2966,7 +2988,7 @@ public class Lower extends TreeTranslator {
// If we are calling a constructor of a local class, add
// free variables after explicit constructor arguments.
ClassSymbol
c
=
(
ClassSymbol
)
constructor
.
owner
;
if
(
(
c
.
owner
.
kind
&
(
VAR
|
MTH
))
!=
0
)
{
if
(
c
.
isLocal
()
)
{
tree
.
args
=
tree
.
args
.
appendList
(
loadFreevars
(
tree
.
pos
(),
freevars
(
c
)));
}
...
...
@@ -2994,7 +3016,7 @@ public class Lower extends TreeTranslator {
makeNullCheck
(
translate
(((
JCFieldAccess
)
tree
.
meth
).
selected
));
tree
.
meth
=
make
.
Ident
(
constructor
);
((
JCIdent
)
tree
.
meth
).
name
=
methName
;
}
else
if
(
(
c
.
owner
.
kind
&
(
MTH
|
VAR
))
!=
0
||
methName
==
names
.
_this
){
}
else
if
(
c
.
isLocal
()
||
methName
==
names
.
_this
){
// local class or this() call
thisArg
=
makeThis
(
tree
.
meth
.
pos
(),
c
.
type
.
getEnclosingType
().
tsym
);
}
else
{
...
...
test/tools/javac/T8022053/UnverifiableInitForNestedLocalClassTest.java
0 → 100644
浏览文件 @
1098e2b6
/*
* Copyright (c) 2013, 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.
*/
/*
* @test
* @bug 8022053
* @summary 8022053: javac generates unverifiable initializer for nested subclass of local class
* @run main UnverifiableInitForNestedLocalClassTest
*/
public
class
UnverifiableInitForNestedLocalClassTest
{
public
static
void
main
(
final
String
[]
args
)
{
test
(
"test"
);
}
static
void
test
(
final
String
arg
)
{
final
String
inlined
=
" inlined "
;
class
LocalClass
{
String
m
()
{
return
"LocalClass "
+
arg
+
inlined
;
}
class
SubClass
extends
LocalClass
{
@Override
String
m
()
{
return
"SubClass "
+
arg
+
inlined
;
}
}
class
SubSubClass
extends
SubClass
{
@Override
String
m
()
{
return
"SubSubClass "
+
arg
+
inlined
;
}
}
class
AnotherLocal
{
class
AnotherSub
extends
LocalClass
{
@Override
String
m
()
{
return
"AnotherSub "
+
arg
+
inlined
;
}
}
}
}
System
.
out
.
println
(
new
LocalClass
().
m
());
System
.
out
.
println
(
new
LocalClass
().
new
SubClass
().
m
());
System
.
out
.
println
(
new
LocalClass
().
new
SubSubClass
().
m
());
System
.
out
.
println
(
new
LocalClass
().
new
AnotherLocal
().
new
AnotherSub
().
m
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录