Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_langtools
提交
ccaec95d
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看板
提交
ccaec95d
编写于
12月 07, 2010
作者:
J
jjg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6999210: javac should be able to warn of anomalous conditions in classfiles
Reviewed-by: mcimadamore, darcy
上级
5b2de8fa
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
183 addition
and
11 deletion
+183
-11
src/share/classes/com/sun/tools/javac/code/Lint.java
src/share/classes/com/sun/tools/javac/code/Lint.java
+5
-0
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
+33
-3
src/share/classes/com/sun/tools/javac/resources/compiler.properties
...classes/com/sun/tools/javac/resources/compiler.properties
+3
-0
src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java
...sses/com/sun/tools/javac/util/RawDiagnosticFormatter.java
+14
-5
test/tools/javac/T6999210.java
test/tools/javac/T6999210.java
+124
-0
test/tools/javac/annotations/6214965/T6214965.out
test/tools/javac/annotations/6214965/T6214965.out
+1
-1
test/tools/javac/annotations/6365854/test1.out
test/tools/javac/annotations/6365854/test1.out
+1
-1
test/tools/javac/annotations/6365854/test2.out
test/tools/javac/annotations/6365854/test2.out
+1
-1
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/Lint.java
浏览文件 @
ccaec95d
...
...
@@ -133,6 +133,11 @@ public class Lint
*/
CAST
(
"cast"
),
/**
* Warn about issues related to classfile contents
*/
CLASSFILE
(
"classfile"
),
/**
* Warn about use of deprecated items.
*/
...
...
src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
浏览文件 @
ccaec95d
...
...
@@ -32,6 +32,7 @@ import java.nio.CharBuffer;
import
java.util.Arrays
;
import
java.util.EnumSet
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
javax.lang.model.SourceVersion
;
...
...
@@ -44,11 +45,13 @@ import static javax.tools.StandardLocation.*;
import
com.sun.tools.javac.comp.Annotate
;
import
com.sun.tools.javac.code.*
;
import
com.sun.tools.javac.code.Lint.LintCategory
;
import
com.sun.tools.javac.code.Type.*
;
import
com.sun.tools.javac.code.Symbol.*
;
import
com.sun.tools.javac.code.Symtab
;
import
com.sun.tools.javac.file.BaseFileObject
;
import
com.sun.tools.javac.util.*
;
import
com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition
;
import
static
com
.
sun
.
tools
.
javac
.
code
.
Flags
.*;
import
static
com
.
sun
.
tools
.
javac
.
code
.
Kinds
.*;
...
...
@@ -102,6 +105,10 @@ public class ClassReader implements Completer {
*/
boolean
allowAnnotations
;
/** Lint option: warn about classfile issues
*/
boolean
lintClassfile
;
/** Switch: preserve parameter names from the variable table.
*/
public
boolean
saveParameterNames
;
...
...
@@ -207,6 +214,11 @@ public class ClassReader implements Completer {
*/
boolean
haveParameterNameIndices
;
/**
* The set of attribute names for which warnings have been generated for the current class
*/
Set
<
Name
>
warnedAttrs
=
new
HashSet
<
Name
>();
/** Get the ClassReader instance for this invocation. */
public
static
ClassReader
instance
(
Context
context
)
{
ClassReader
instance
=
context
.
get
(
classReaderKey
);
...
...
@@ -279,6 +291,8 @@ public class ClassReader implements Completer {
typevars
=
new
Scope
(
syms
.
noSymbol
);
debugJSR308
=
options
.
isSet
(
"TA:reader"
);
lintClassfile
=
Lint
.
instance
(
context
).
isEnabled
(
LintCategory
.
CLASSFILE
);
initAttributeReaders
();
}
...
...
@@ -870,7 +884,22 @@ public class ClassReader implements Completer {
}
boolean
accepts
(
AttributeKind
kind
)
{
return
kinds
.
contains
(
kind
)
&&
majorVersion
>=
version
.
major
;
if
(
kinds
.
contains
(
kind
))
{
if
(
majorVersion
>
version
.
major
||
(
majorVersion
==
version
.
major
&&
minorVersion
>=
version
.
minor
))
return
true
;
if
(
lintClassfile
&&
!
warnedAttrs
.
contains
(
name
))
{
JavaFileObject
prev
=
log
.
useSource
(
currentClassFile
);
try
{
log
.
warning
(
LintCategory
.
CLASSFILE
,
(
DiagnosticPosition
)
null
,
"future.attr"
,
name
,
version
.
major
,
version
.
minor
,
majorVersion
,
minorVersion
);
}
finally
{
log
.
useSource
(
prev
);
}
warnedAttrs
.
add
(
name
);
}
}
return
false
;
}
abstract
void
read
(
Symbol
sym
,
int
attrLen
);
...
...
@@ -889,7 +918,7 @@ public class ClassReader implements Completer {
protected
Map
<
Name
,
AttributeReader
>
attributeReaders
=
new
HashMap
<
Name
,
AttributeReader
>();
pr
otected
void
initAttributeReaders
()
{
pr
ivate
void
initAttributeReaders
()
{
AttributeReader
[]
readers
=
{
// v45.3 attributes
...
...
@@ -1561,7 +1590,7 @@ public class ClassReader implements Completer {
public
void
accept
(
Visitor
v
)
{
((
ProxyVisitor
)
v
).
visitCompoundAnnotationProxy
(
this
);
}
@Override
public
String
toString
()
{
StringBu
ffer
buf
=
new
StringBuff
er
();
StringBu
ilder
buf
=
new
StringBuild
er
();
buf
.
append
(
"@"
);
buf
.
append
(
type
.
tsym
.
getQualifiedName
());
buf
.
append
(
"/*proxy*/{"
);
...
...
@@ -2286,6 +2315,7 @@ public class ClassReader implements Completer {
throw
new
CompletionFailure
(
c
,
"user-selected completion failure by class name"
);
}
currentOwner
=
c
;
warnedAttrs
.
clear
();
JavaFileObject
classfile
=
c
.
classfile
;
if
(
classfile
!=
null
)
{
JavaFileObject
previousClassFile
=
currentClassFile
;
...
...
src/share/classes/com/sun/tools/javac/resources/compiler.properties
浏览文件 @
ccaec95d
...
...
@@ -767,6 +767,9 @@ compiler.warn.static.not.qualified.by.type=\
compiler.warn.source.no.bootclasspath
=
\
bootstrap class path not set in conjunction with -source {0}
compiler.warn.future.attr
=
\
{0} attribute introduced in version {1}.{2} class files is ignored in version {3}.{4} class files
# Warnings related to annotation processing
compiler.warn.proc.package.does.not.exist
=
\
package {0} does not exist
...
...
src/share/classes/com/sun/tools/javac/util/RawDiagnosticFormatter.java
浏览文件 @
ccaec95d
...
...
@@ -27,6 +27,7 @@ package com.sun.tools.javac.util;
import
java.util.Collection
;
import
java.util.EnumSet
;
import
java.util.Locale
;
import
javax.tools.JavaFileObject
;
import
com.sun.tools.javac.api.DiagnosticFormatter.Configuration.*
;
import
com.sun.tools.javac.api.Formattable
;
...
...
@@ -62,7 +63,7 @@ public final class RawDiagnosticFormatter extends AbstractDiagnosticFormatter {
//provide common default formats
public
String
formatDiagnostic
(
JCDiagnostic
d
,
Locale
l
)
{
try
{
StringBu
ffer
buf
=
new
StringBuff
er
();
StringBu
ilder
buf
=
new
StringBuild
er
();
if
(
d
.
getPosition
()
!=
Position
.
NOPOS
)
{
buf
.
append
(
formatSource
(
d
,
false
,
null
));
buf
.
append
(
':'
);
...
...
@@ -71,16 +72,22 @@ public final class RawDiagnosticFormatter extends AbstractDiagnosticFormatter {
buf
.
append
(
formatPosition
(
d
,
COLUMN
,
null
));
buf
.
append
(
':'
);
}
else
if
(
d
.
getSource
()
!=
null
&&
d
.
getSource
().
getKind
()
==
JavaFileObject
.
Kind
.
CLASS
)
{
buf
.
append
(
formatSource
(
d
,
false
,
null
));
buf
.
append
(
":-:-:"
);
}
else
buf
.
append
(
'-'
);
buf
.
append
(
' '
);
buf
.
append
(
formatMessage
(
d
,
null
));
if
(
displaySource
(
d
))
buf
.
append
(
"\n"
+
formatSourceLine
(
d
,
0
));
if
(
displaySource
(
d
))
{
buf
.
append
(
"\n"
);
buf
.
append
(
formatSourceLine
(
d
,
0
));
}
return
buf
.
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
//
e.printStackTrace();
return
null
;
}
}
...
...
@@ -96,7 +103,9 @@ public final class RawDiagnosticFormatter extends AbstractDiagnosticFormatter {
buf
.
append
(
",{"
);
for
(
String
sub
:
formatSubdiagnostics
(
d
,
null
))
{
buf
.
append
(
sep
);
buf
.
append
(
"("
+
sub
+
")"
);
buf
.
append
(
"("
);
buf
.
append
(
sub
);
buf
.
append
(
")"
);
sep
=
","
;
}
buf
.
append
(
'}'
);
...
...
test/tools/javac/T6999210.java
0 → 100644
浏览文件 @
ccaec95d
/*
* Copyright (c) 2010, 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 6999210
* @summary javac should be able to warn of anomalous conditions in classfiles
*/
import
java.io.*
;
import
java.util.*
;
public
class
T6999210
{
public
static
void
main
(
String
...
args
)
throws
Exception
{
new
T6999210
().
run
();
}
void
run
()
throws
Exception
{
File
srcDir
=
new
File
(
"src"
);
File
classesDir
=
new
File
(
"classes"
);
classesDir
.
mkdirs
();
File
c_java
=
writeFile
(
srcDir
,
"C.java"
,
"class C<T> { }"
);
compile
(
"-d"
,
classesDir
.
getPath
(),
c_java
.
getPath
());
File
c_class
=
new
File
(
classesDir
,
"C.class"
);
setMajorVersion
(
c_class
,
48
);
File
d_java
=
writeFile
(
srcDir
,
"D.java"
,
"class D { C c; }"
);
// verify no warning if -Xlint:classfile not enabled
String
out1
=
compile
(
"-d"
,
classesDir
.
getPath
(),
"-classpath"
,
classesDir
.
getPath
(),
d_java
.
getPath
());
if
(
out1
.
length
()
>
0
)
error
(
"unexpected output from javac"
);
// sanity check of warning when -XDrawDiagnostics not used
String
out2
=
compile
(
"-d"
,
classesDir
.
getPath
(),
"-classpath"
,
classesDir
.
getPath
(),
"-Xlint:classfile"
,
d_java
.
getPath
());
if
(!
out2
.
contains
(
"[classfile]"
))
error
(
"expected output \"[classfile]\" not found"
);
// check specific details, using -XDrawDiagnostics
String
out3
=
compile
(
"-d"
,
classesDir
.
getPath
(),
"-classpath"
,
classesDir
.
getPath
(),
"-Xlint:classfile"
,
"-XDrawDiagnostics"
,
d_java
.
getPath
());
String
expect
=
"C.class:-:-: compiler.warn.future.attr: Signature, 49, 0, 48, 0"
;
if
(!
out3
.
contains
(
expect
))
error
(
"expected output \""
+
expect
+
"\" not found"
);
if
(
errors
>
0
)
throw
new
Exception
(
errors
+
" errors occurred"
);
}
String
compile
(
String
...
args
)
throws
Exception
{
System
.
err
.
println
(
"compile: "
+
Arrays
.
asList
(
args
));
StringWriter
sw
=
new
StringWriter
();
PrintWriter
pw
=
new
PrintWriter
(
sw
);
int
rc
=
com
.
sun
.
tools
.
javac
.
Main
.
compile
(
args
,
pw
);
pw
.
close
();
String
out
=
sw
.
toString
();
if
(
out
.
length
()
>
0
)
System
.
err
.
println
(
out
);
if
(
rc
!=
0
)
throw
new
Exception
(
"compilation failed, rc="
+
rc
);
return
out
;
}
void
setMajorVersion
(
File
f
,
int
major
)
throws
IOException
{
int
len
=
(
int
)
f
.
length
();
byte
[]
data
=
new
byte
[
len
];
try
(
DataInputStream
in
=
new
DataInputStream
(
new
FileInputStream
(
f
)))
{
in
.
readFully
(
data
);
}
// u4 magic
// u2 minor
data
[
6
]
=
(
byte
)
(
major
>>
8
);
data
[
7
]
=
(
byte
)
(
major
&
0xff
);
try
(
FileOutputStream
out
=
new
FileOutputStream
(
f
))
{
out
.
write
(
data
);
}
}
File
writeFile
(
File
dir
,
String
path
,
String
body
)
throws
IOException
{
File
f
=
new
File
(
dir
,
path
);
f
.
getParentFile
().
mkdirs
();
try
(
FileWriter
out
=
new
FileWriter
(
f
))
{
out
.
write
(
body
);
}
return
f
;
}
void
error
(
String
msg
)
{
System
.
err
.
println
(
"Error: "
+
msg
);
errors
++;
}
int
errors
;
}
test/tools/javac/annotations/6214965/T6214965.out
浏览文件 @
ccaec95d
-
compiler.warn.annotation.method.not.found: CompilerAnnotationTest2, name2
CompilerAnnotationTest.class:-:-:
compiler.warn.annotation.method.not.found: CompilerAnnotationTest2, name2
1 warning
test/tools/javac/annotations/6365854/test1.out
浏览文件 @
ccaec95d
-
compiler.warn.annotation.method.not.found.reason: test.annotation.TestAnnotation, test, (compiler.misc.class.file.not.found: test.annotation.TestAnnotation)
TestCore.class:-:-:
compiler.warn.annotation.method.not.found.reason: test.annotation.TestAnnotation, test, (compiler.misc.class.file.not.found: test.annotation.TestAnnotation)
1 warning
test/tools/javac/annotations/6365854/test2.out
浏览文件 @
ccaec95d
-
compiler.warn.annotation.method.not.found: test.annotation.TestAnnotation, test
TestCore.class:-:-:
compiler.warn.annotation.method.not.found: test.annotation.TestAnnotation, test
1 warning
test/tools/javac/diags/examples.not-yet.txt
浏览文件 @
ccaec95d
...
...
@@ -104,6 +104,7 @@ compiler.misc.wrong.version # ClassReader
compiler.warn.annotation.method.not.found # ClassReader
compiler.warn.annotation.method.not.found.reason # ClassReader
compiler.warn.big.major.version # ClassReader
compiler.warn.future.attr # ClassReader
compiler.warn.illegal.char.for.encoding
compiler.warn.invalid.archive.file
compiler.warn.override.bridge
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录