Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
6bcdc301
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6bcdc301
编写于
2月 03, 2011
作者:
K
ksrini
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6968053: (launcher) hide exceptions under certain launcher failures
Reviewed-by: mchung
上级
729dd870
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
108 addition
and
71 deletion
+108
-71
src/share/bin/java.c
src/share/bin/java.c
+3
-0
src/share/classes/sun/launcher/LauncherHelper.java
src/share/classes/sun/launcher/LauncherHelper.java
+59
-57
src/share/classes/sun/launcher/resources/launcher.properties
src/share/classes/sun/launcher/resources/launcher.properties
+6
-3
src/share/classes/sun/misc/VM.java
src/share/classes/sun/misc/VM.java
+6
-0
test/tools/launcher/Arrrghs.java
test/tools/launcher/Arrrghs.java
+34
-11
未找到文件。
src/share/bin/java.c
浏览文件 @
6bcdc301
...
...
@@ -244,6 +244,7 @@ JLI_Launch(int argc, char ** argv, /* main argc, argc */
for
(
i
=
0
;
i
<
argc
;
i
++
)
{
printf
(
"argv[%d] = %s
\n
"
,
i
,
argv
[
i
]);
}
AddOption
(
"-Dsun.java.launcher.diag=true"
,
NULL
);
}
CreateExecutionEnvironment
(
&
argc
,
&
argv
,
...
...
@@ -1009,6 +1010,8 @@ ParseArguments(int *pargc, char ***pargv,
}
else
if
(
JLI_StrCmp
(
arg
,
"-XshowSettings"
)
==
0
||
JLI_StrCCmp
(
arg
,
"-XshowSettings:"
)
==
0
)
{
showSettings
=
arg
;
}
else
if
(
JLI_StrCmp
(
arg
,
"-Xdiag"
)
==
0
)
{
AddOption
(
"-Dsun.java.launcher.diag=true"
,
NULL
);
/*
* The following case provide backward compatibility with old-style
* command line options.
...
...
src/share/classes/sun/launcher/LauncherHelper.java
浏览文件 @
6bcdc301
...
...
@@ -63,8 +63,6 @@ import java.util.jar.Manifest;
public
enum
LauncherHelper
{
INSTANCE
;
private
static
final
String
defaultBundleName
=
"sun.launcher.resources.launcher"
;
private
static
final
String
MAIN_CLASS
=
"Main-Class"
;
private
static
StringBuilder
outBuf
=
new
StringBuilder
();
...
...
@@ -76,11 +74,14 @@ public enum LauncherHelper {
private
static
final
String
PROP_SETTINGS
=
"Property settings:"
;
private
static
final
String
LOCALE_SETTINGS
=
"Locale settings:"
;
private
static
synchronized
ResourceBundle
getLauncherResourceBundle
()
{
if
(
javarb
==
null
)
{
javarb
=
ResourceBundle
.
getBundle
(
defaultBundleName
);
}
return
javarb
;
// sync with java.c and sun.misc.VM
private
static
final
String
diagprop
=
"sun.java.launcher.diag"
;
private
static
final
String
defaultBundleName
=
"sun.launcher.resources.launcher"
;
private
static
class
ResourceBundleHolder
{
private
static
final
ResourceBundle
RB
=
ResourceBundle
.
getBundle
(
defaultBundleName
);
}
/*
...
...
@@ -308,7 +309,7 @@ public enum LauncherHelper {
* apply any arguments that we might pass.
*/
private
static
String
getLocalizedMessage
(
String
key
,
Object
...
args
)
{
String
msg
=
getLauncherResourceBundle
()
.
getString
(
key
);
String
msg
=
ResourceBundleHolder
.
RB
.
getString
(
key
);
return
(
args
!=
null
)
?
MessageFormat
.
format
(
msg
,
args
)
:
msg
;
}
...
...
@@ -380,18 +381,18 @@ public enum LauncherHelper {
File
.
pathSeparator
));
}
static
String
getMainClassFromJar
(
String
jarname
)
throws
IOException
{
static
String
getMainClassFromJar
(
PrintStream
ostream
,
String
jarname
)
{
try
{
JarFile
jarFile
=
null
;
try
{
jarFile
=
new
JarFile
(
jarname
);
Manifest
manifest
=
jarFile
.
getManifest
();
if
(
manifest
==
null
)
{
throw
new
IOException
(
"manifest not found in "
+
jarname
);
abort
(
ostream
,
null
,
"java.launcher.jar.error2"
,
jarname
);
}
Attributes
mainAttrs
=
manifest
.
getMainAttributes
();
if
(
mainAttrs
==
null
)
{
throw
new
IOException
(
"no main mainifest attributes, in "
+
jarname
);
abort
(
ostream
,
null
,
"java.launcher.jar.error3"
,
jarname
);
}
return
mainAttrs
.
getValue
(
MAIN_CLASS
).
trim
();
}
finally
{
...
...
@@ -399,6 +400,10 @@ public enum LauncherHelper {
jarFile
.
close
();
}
}
}
catch
(
IOException
ioe
)
{
abort
(
ostream
,
ioe
,
"java.launcher.jar.error1"
,
jarname
);
}
return
null
;
}
...
...
@@ -409,6 +414,20 @@ public enum LauncherHelper {
private
static
final
int
LM_CLASS
=
1
;
private
static
final
int
LM_JAR
=
2
;
static
void
abort
(
PrintStream
ostream
,
Throwable
t
,
String
msgKey
,
Object
...
args
)
{
if
(
msgKey
!=
null
)
{
ostream
.
println
(
getLocalizedMessage
(
msgKey
,
args
));
}
if
(
sun
.
misc
.
VM
.
getSavedProperty
(
diagprop
)
!=
null
)
{
if
(
t
!=
null
)
{
t
.
printStackTrace
();
}
else
{
Thread
.
currentThread
().
dumpStack
();
}
}
System
.
exit
(
1
);
}
/**
* This method does the following:
* 1. gets the classname from a Jar's manifest, if necessary
...
...
@@ -426,15 +445,12 @@ public enum LauncherHelper {
* @param isJar
* @param name
* @return
* @throws java.io.IOException
*/
public
static
Class
<?>
checkAndLoadMain
(
boolean
printToStderr
,
int
mode
,
String
what
)
throws
IOException
{
ClassLoader
ld
=
ClassLoader
.
getSystemClassLoader
();
String
what
)
{
final
PrintStream
ostream
=
(
printToStderr
)
?
System
.
err
:
System
.
out
;
final
ClassLoader
ld
=
ClassLoader
.
getSystemClassLoader
();
// get the class name
String
cn
=
null
;
switch
(
mode
)
{
...
...
@@ -442,23 +458,18 @@ public enum LauncherHelper {
cn
=
what
;
break
;
case
LM_JAR:
cn
=
getMainClassFromJar
(
what
);
cn
=
getMainClassFromJar
(
ostream
,
what
);
break
;
default
:
// should never happen
throw
new
InternalError
(
""
+
mode
+
": Unknown launch mode"
);
}
cn
=
cn
.
replace
(
'/'
,
'.'
);
PrintStream
ostream
=
(
printToStderr
)
?
System
.
err
:
System
.
out
;
Class
<?>
c
=
null
;
try
{
c
=
ld
.
loadClass
(
cn
);
}
catch
(
ClassNotFoundException
cnfe
)
{
ostream
.
println
(
getLocalizedMessage
(
"java.launcher.cls.error1"
,
cn
));
NoClassDefFoundError
ncdfe
=
new
NoClassDefFoundError
(
cn
);
ncdfe
.
initCause
(
cnfe
);
throw
ncdfe
;
abort
(
ostream
,
cnfe
,
"java.launcher.cls.error1"
,
cn
);
}
signatureDiagnostic
(
ostream
,
c
);
return
c
;
...
...
@@ -470,9 +481,7 @@ public enum LauncherHelper {
try
{
method
=
clazz
.
getMethod
(
"main"
,
String
[].
class
);
}
catch
(
NoSuchMethodException
nsme
)
{
ostream
.
println
(
getLocalizedMessage
(
"java.launcher.cls.error4"
,
classname
));
throw
new
RuntimeException
(
"Main method not found in "
+
classname
);
abort
(
ostream
,
null
,
"java.launcher.cls.error4"
,
classname
);
}
/*
* getMethod (above) will choose the correct method, based
...
...
@@ -481,17 +490,10 @@ public enum LauncherHelper {
*/
int
mod
=
method
.
getModifiers
();
if
(!
Modifier
.
isStatic
(
mod
))
{
ostream
.
println
(
getLocalizedMessage
(
"java.launcher.cls.error2"
,
"static"
,
classname
));
throw
new
RuntimeException
(
"Main method is not static in class "
+
classname
);
abort
(
ostream
,
null
,
"java.launcher.cls.error2"
,
"static"
,
classname
);
}
if
(
method
.
getReturnType
()
!=
java
.
lang
.
Void
.
TYPE
)
{
ostream
.
println
(
getLocalizedMessage
(
"java.launcher.cls.error3"
,
classname
));
throw
new
RuntimeException
(
"Main method must return a value"
+
" of type void in class "
+
classname
);
abort
(
ostream
,
null
,
"java.launcher.cls.error3"
,
classname
);
}
return
;
}
...
...
src/share/classes/sun/launcher/resources/launcher.properties
浏览文件 @
6bcdc301
...
...
@@ -84,6 +84,7 @@ java.launcher.X.usage=\
\
append to end of bootstrap class path
\n\
\
-Xbootclasspath/p:<directories and zip/jar files separated by {0}>
\n\
\
prepend in front of bootstrap class path
\n\
\
-Xdiag show additional diagnostic messages
\n\
\
-Xnoclassgc disable class garbage collection
\n\
\
-Xincgc enable incremental garbage collection
\n\
\
-Xloggc:<file> log GC status to a file with time stamps
\n\
...
...
@@ -109,7 +110,7 @@ java.launcher.X.usage=\
The -X options are non-standard and subject to change without notice.
\n
java.launcher.cls.error1
=
\
Error: Could not find main class {0}
Error: Could not find
or load
main class {0}
java.launcher.cls.error2
=
\
Error: Main method is not {0} in class {1}, please define the main method as:
\n\
\
public static void main(String[] args)
...
...
@@ -120,5 +121,7 @@ java.launcher.cls.error3=\
java.launcher.cls.error4
=
\
Error: Main method not found in class {0}, please define the main method as:
\n\
\
public static void main(String[] args)
java.launcher.jar.error1
=
\
Error: An unexpected error occurred while trying to open file {0}
java.launcher.jar.error2
=
manifest not found in {0}
java.launcher.jar.error3
=
no main manifest attribute, in {0}
src/share/classes/sun/misc/VM.java
浏览文件 @
6bcdc301
...
...
@@ -235,6 +235,9 @@ public class VM {
return
savedProps
.
getProperty
(
key
);
}
// TODO: the Property Management needs to be refactored and
// the appropriate prop keys need to be accessible to the
// calling classes to avoid duplication of keys.
private
static
final
Properties
savedProps
=
new
Properties
();
// Save a private copy of the system properties and remove
...
...
@@ -283,6 +286,9 @@ public class VM {
// used by java.util.zip.ZipFile
props
.
remove
(
"sun.zip.disableMemoryMapping"
);
// used by sun.launcher.LauncherHelper
props
.
remove
(
"sun.java.launcher.diag"
);
}
// Initialize any miscellenous operating system settings that need to be
...
...
test/tools/launcher/Arrrghs.java
浏览文件 @
6bcdc301
...
...
@@ -24,7 +24,7 @@
/**
* @test
* @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938
* 6894719
* 6894719
6968053
* @summary Argument parsing validation.
* @compile -XDignore.symbol.file Arrrghs.java TestHelper.java
* @run main Arrrghs
...
...
@@ -250,13 +250,11 @@ public class Arrrghs {
TestHelper
.
createJar
(
"MIA"
,
new
File
(
"some.jar"
),
new
File
(
"Foo"
),
(
String
[])
null
);
tr
=
TestHelper
.
doExec
(
TestHelper
.
javaCmd
,
"-jar"
,
"some.jar"
);
tr
.
contains
(
"Error: Could not find main class MIA"
);
tr
.
contains
(
"java.lang.NoClassDefFoundError: MIA"
);
tr
.
contains
(
"Error: Could not find or load main class MIA"
);
System
.
out
.
println
(
tr
);
// use classpath to check
tr
=
TestHelper
.
doExec
(
TestHelper
.
javaCmd
,
"-cp"
,
"some.jar"
,
"MIA"
);
tr
.
contains
(
"Error: Could not find main class MIA"
);
tr
.
contains
(
"java.lang.NoClassDefFoundError: MIA"
);
tr
.
contains
(
"Error: Could not find or load main class MIA"
);
System
.
out
.
println
(
tr
);
// incorrect method access
...
...
@@ -326,6 +324,30 @@ public class Arrrghs {
tr
.
checkPositive
();
System
.
out
.
println
(
tr
);
}
// tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if
// the suppressed stack traces are exposed.
static
void
runDiagOptionTests
()
throws
FileNotFoundException
{
TestHelper
.
TestResult
tr
=
null
;
// a missing class
TestHelper
.
createJar
(
"MIA"
,
new
File
(
"some.jar"
),
new
File
(
"Foo"
),
(
String
[])
null
);
tr
=
TestHelper
.
doExec
(
TestHelper
.
javaCmd
,
"-Xdiag"
,
"-jar"
,
"some.jar"
);
tr
.
contains
(
"Error: Could not find or load main class MIA"
);
tr
.
contains
(
"java.lang.ClassNotFoundException: MIA"
);
System
.
out
.
println
(
tr
);
// use classpath to check
tr
=
TestHelper
.
doExec
(
TestHelper
.
javaCmd
,
"-Xdiag"
,
"-cp"
,
"some.jar"
,
"MIA"
);
tr
.
contains
(
"Error: Could not find or load main class MIA"
);
tr
.
contains
(
"java.lang.ClassNotFoundException: MIA"
);
System
.
out
.
println
(
tr
);
// a missing class on the classpath
tr
=
TestHelper
.
doExec
(
TestHelper
.
javaCmd
,
"-Xdiag"
,
"NonExistentClass"
);
tr
.
contains
(
"Error: Could not find or load main class NonExistentClass"
);
tr
.
contains
(
"java.lang.ClassNotFoundException: NonExistentClass"
);
System
.
out
.
println
(
tr
);
}
static
void
test6894719
()
{
// test both arguments to ensure they exist
...
...
@@ -352,6 +374,7 @@ public class Arrrghs {
runBasicErrorMessageTests
();
runMainMethodTests
();
test6894719
();
runDiagOptionTests
();
if
(
TestHelper
.
testExitValue
>
0
)
{
System
.
out
.
println
(
"Total of "
+
TestHelper
.
testExitValue
+
" failed"
);
System
.
exit
(
1
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录