Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
2ce80ac6
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看板
提交
2ce80ac6
编写于
4月 30, 2014
作者:
P
pgovereau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8039026: Definitely unassigned field can be accessed
Reviewed-by: vromero, jlahoda
上级
6e6e66ef
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
64 addition
and
9 deletion
+64
-9
src/share/classes/com/sun/tools/javac/code/Source.java
src/share/classes/com/sun/tools/javac/code/Source.java
+3
-0
src/share/classes/com/sun/tools/javac/comp/Flow.java
src/share/classes/com/sun/tools/javac/comp/Flow.java
+34
-7
src/share/classes/com/sun/tools/javac/jvm/Gen.java
src/share/classes/com/sun/tools/javac/jvm/Gen.java
+2
-2
test/tools/javac/DefiniteAssignment/T8039026.java
test/tools/javac/DefiniteAssignment/T8039026.java
+21
-0
test/tools/javac/DefiniteAssignment/T8039026.out
test/tools/javac/DefiniteAssignment/T8039026.out
+4
-0
未找到文件。
src/share/classes/com/sun/tools/javac/code/Source.java
浏览文件 @
2ce80ac6
...
...
@@ -191,6 +191,9 @@ public enum Source {
public
boolean
allowObjectToPrimitiveCast
()
{
return
compareTo
(
JDK1_7
)
>=
0
;
}
public
boolean
enforceThisDotInit
()
{
return
compareTo
(
JDK1_7
)
>=
0
;
}
public
boolean
allowPoly
()
{
return
compareTo
(
JDK1_8
)
>=
0
;
}
...
...
src/share/classes/com/sun/tools/javac/comp/Flow.java
浏览文件 @
2ce80ac6
...
...
@@ -197,6 +197,7 @@ public class Flow {
private
final
boolean
allowImprovedRethrowAnalysis
;
private
final
boolean
allowImprovedCatchAnalysis
;
private
final
boolean
allowEffectivelyFinalInInnerClasses
;
private
final
boolean
enforceThisDotInit
;
public
static
Flow
instance
(
Context
context
)
{
Flow
instance
=
context
.
get
(
flowKey
);
...
...
@@ -207,7 +208,7 @@ public class Flow {
public
void
analyzeTree
(
Env
<
AttrContext
>
env
,
TreeMaker
make
)
{
new
AliveAnalyzer
().
analyzeTree
(
env
,
make
);
new
AssignAnalyzer
(
log
,
syms
,
lint
,
names
).
analyzeTree
(
env
);
new
AssignAnalyzer
(
log
,
syms
,
lint
,
names
,
enforceThisDotInit
).
analyzeTree
(
env
);
new
FlowAnalyzer
().
analyzeTree
(
env
,
make
);
new
CaptureAnalyzer
().
analyzeTree
(
env
,
make
);
}
...
...
@@ -239,7 +240,7 @@ public class Flow {
//related errors, which will allow for more errors to be detected
Log
.
DiagnosticHandler
diagHandler
=
new
Log
.
DiscardDiagnosticHandler
(
log
);
try
{
new
AssignAnalyzer
(
log
,
syms
,
lint
,
names
).
analyzeTree
(
env
);
new
AssignAnalyzer
(
log
,
syms
,
lint
,
names
,
enforceThisDotInit
).
analyzeTree
(
env
);
LambdaFlowAnalyzer
flowAnalyzer
=
new
LambdaFlowAnalyzer
();
flowAnalyzer
.
analyzeTree
(
env
,
that
,
make
);
return
flowAnalyzer
.
inferredThrownTypes
;
...
...
@@ -289,6 +290,7 @@ public class Flow {
allowImprovedRethrowAnalysis
=
source
.
allowImprovedRethrowAnalysis
();
allowImprovedCatchAnalysis
=
source
.
allowImprovedCatchAnalysis
();
allowEffectivelyFinalInInnerClasses
=
source
.
allowEffectivelyFinalInInnerClasses
();
enforceThisDotInit
=
source
.
enforceThisDotInit
();
}
/**
...
...
@@ -1427,6 +1429,8 @@ public class Flow {
protected
Names
names
;
final
boolean
enforceThisDotInit
;
public
static
class
AbstractAssignPendingExit
extends
BaseAnalyzer
.
PendingExit
{
final
Bits
inits
;
...
...
@@ -1449,7 +1453,7 @@ public class Flow {
}
}
public
AbstractAssignAnalyzer
(
Bits
inits
,
Symtab
syms
,
Names
names
)
{
public
AbstractAssignAnalyzer
(
Bits
inits
,
Symtab
syms
,
Names
names
,
boolean
enforceThisDotInit
)
{
this
.
inits
=
inits
;
uninits
=
new
Bits
();
uninitsTry
=
new
Bits
();
...
...
@@ -1459,6 +1463,7 @@ public class Flow {
uninitsWhenFalse
=
new
Bits
(
true
);
this
.
syms
=
syms
;
this
.
names
=
names
;
this
.
enforceThisDotInit
=
enforceThisDotInit
;
}
private
boolean
isInitialConstructor
=
false
;
...
...
@@ -2280,12 +2285,34 @@ public class Flow {
public
void
visitAssign
(
JCAssign
tree
)
{
JCTree
lhs
=
TreeInfo
.
skipParens
(
tree
.
lhs
);
if
(!
(
lhs
instanceof
JCIdent
))
{
if
(!
isIdentOrThisDotIdent
(
lhs
))
scanExpr
(
lhs
);
}
scanExpr
(
tree
.
rhs
);
letInit
(
lhs
);
}
private
boolean
isIdentOrThisDotIdent
(
JCTree
lhs
)
{
if
(
lhs
.
hasTag
(
IDENT
))
return
true
;
if
(!
lhs
.
hasTag
(
SELECT
))
return
false
;
JCFieldAccess
fa
=
(
JCFieldAccess
)
lhs
;
return
fa
.
selected
.
hasTag
(
IDENT
)
&&
((
JCIdent
)
fa
.
selected
).
name
==
names
.
_this
;
}
// check fields accessed through this.<field> are definitely
// assigned before reading their value
public
void
visitSelect
(
JCFieldAccess
tree
)
{
super
.
visitSelect
(
tree
);
if
(
enforceThisDotInit
&&
tree
.
selected
.
hasTag
(
IDENT
)
&&
((
JCIdent
)
tree
.
selected
).
name
==
names
.
_this
&&
tree
.
sym
.
kind
==
VAR
)
{
checkInit
(
tree
.
pos
(),
(
VarSymbol
)
tree
.
sym
);
}
}
public
void
visitAssignop
(
JCAssignOp
tree
)
{
scanExpr
(
tree
.
lhs
);
...
...
@@ -2419,8 +2446,8 @@ public class Flow {
}
}
public
AssignAnalyzer
(
Log
log
,
Symtab
syms
,
Lint
lint
,
Names
names
)
{
super
(
new
Bits
(),
syms
,
names
);
public
AssignAnalyzer
(
Log
log
,
Symtab
syms
,
Lint
lint
,
Names
names
,
boolean
enforceThisDotInit
)
{
super
(
new
Bits
(),
syms
,
names
,
enforceThisDotInit
);
this
.
log
=
log
;
this
.
lint
=
lint
;
}
...
...
src/share/classes/com/sun/tools/javac/jvm/Gen.java
浏览文件 @
2ce80ac6
/*
* 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
...
...
@@ -2818,7 +2818,7 @@ public class Gen extends JCTree.Visitor {
}
private
LVTAssignAnalyzer
(
LVTRanges
lvtRanges
,
Symtab
syms
,
Names
names
)
{
super
(
new
LVTBits
(),
syms
,
names
);
super
(
new
LVTBits
(),
syms
,
names
,
false
);
lvtInits
=
(
LVTBits
)
inits
;
this
.
lvtRanges
=
lvtRanges
;
}
...
...
test/tools/javac/DefiniteAssignment/T8039026.java
0 → 100644
浏览文件 @
2ce80ac6
/*
* @test /nodynamiccopyright/
* @bug 8039026
* @summary Definitely unassigned field can be accessed
* @compile/fail/ref=T8039026.out -XDrawDiagnostics T8039026.java
*/
public
class
T8039026
{
final
int
x
,
y
,
z
;
final
int
a
=
this
.
y
;
// <- error
{
int
b
=
true
?
this
.
x
:
0
;
// <- error
System
.
out
.
println
(
this
.
x
);
// <- error
this
.
y
=
1
;
}
T8039026
()
{
this
.
x
=
1
;
// <- no error!
this
.
y
=
1
;
// <- error
this
.
z
=
this
.
x
;
// <- no error
}
}
test/tools/javac/DefiniteAssignment/T8039026.out
0 → 100644
浏览文件 @
2ce80ac6
T8039026.java:10:23: compiler.err.var.might.not.have.been.initialized: y
T8039026.java:12:28: compiler.err.var.might.not.have.been.initialized: x
T8039026.java:18:13: compiler.err.var.might.already.be.assigned: y
3 errors
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录