6684582: Launcher needs improved error reporting
Indicate the missing main class in the error message Reviewed-by: darcy, kbr
This commit is contained in:
parent
bbe29fa484
commit
da0bf7574c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 2005-2008 Sun Microsystems, Inc. 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
|
||||
@ -50,7 +50,7 @@
|
||||
#define JAR_ERROR2 "Error: Unable to access jarfile %s"
|
||||
#define JAR_ERROR3 "Error: Invalid or corrupt jarfile %s"
|
||||
|
||||
#define CLS_ERROR1 "Error: Could not find the main class.\n" JNI_ERROR
|
||||
#define CLS_ERROR1 "Error: Could not find the main class %s.\n" JNI_ERROR
|
||||
#define CLS_ERROR2 "Error: Failed to load Main Class: %s\n%s"
|
||||
#define CLS_ERROR3 "Error: No main method found in specified class.\n" GEN_ERROR
|
||||
#define CLS_ERROR4 "Error: Main method not public\n" GEN_ERROR
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 1995-2008 Sun Microsystems, Inc. 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
|
||||
@ -414,7 +414,7 @@ JavaMain(void * _args)
|
||||
mainClass = LoadClass(env, classname);
|
||||
if(mainClass == NULL) { /* exception occured */
|
||||
ReportExceptionDescription(env);
|
||||
ReportErrorMessage(CLS_ERROR1);
|
||||
ReportErrorMessage(CLS_ERROR1, classname);
|
||||
goto leave;
|
||||
}
|
||||
(*env)->ReleaseStringUTFChars(env, mainClassName, classname);
|
||||
@ -433,7 +433,7 @@ JavaMain(void * _args)
|
||||
mainClass = LoadClass(env, classname);
|
||||
if(mainClass == NULL) { /* exception occured */
|
||||
ReportExceptionDescription(env);
|
||||
ReportErrorMessage(CLS_ERROR1);
|
||||
ReportErrorMessage(CLS_ERROR1, classname);
|
||||
goto leave;
|
||||
}
|
||||
(*env)->ReleaseStringUTFChars(env, mainClassName, classname);
|
||||
|
@ -1,17 +1,5 @@
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/*
|
||||
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* Copyright 2007-2008 Sun Microsystems, Inc. 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
|
||||
@ -33,8 +21,19 @@ import java.util.StringTokenizer;
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
public class Arrrghs{
|
||||
public class Arrrghs {
|
||||
|
||||
/**
|
||||
* A group of tests to ensure that arguments are passed correctly to
|
||||
@ -113,12 +112,10 @@ public class Arrrghs{
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static boolean doExec0(ProcessBuilder pb, String expectedArguments) {
|
||||
boolean retval = false;
|
||||
try {
|
||||
pb.redirectErrorStream(_debug);
|
||||
pb.redirectErrorStream(true);
|
||||
Process p = pb.start();
|
||||
retval = detectCookie(p.getInputStream(), expectedArguments);
|
||||
p.waitFor();
|
||||
@ -167,7 +164,6 @@ public class Arrrghs{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_debug) System.out.println("Starting Arrrghs tests");
|
||||
// Basic test
|
||||
if (!doExec("-a -b -c -d")) exitValue++;
|
||||
|
@ -1,13 +1,13 @@
|
||||
#!/bin/sh
|
||||
# @test Arrrghs.sh
|
||||
# @bug 5030233 6214916 6356475 6571029
|
||||
# @bug 5030233 6214916 6356475 6571029 6684582
|
||||
# @build Arrrghs
|
||||
# @run shell Arrrghs.sh
|
||||
# @summary Argument parsing validation.
|
||||
# @author Joseph E. Kowalski
|
||||
|
||||
#
|
||||
# Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
|
||||
# Copyright 2004-2008 Sun Microsystems, Inc. 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
|
||||
@ -103,6 +103,44 @@ TestHelp() {
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Test to ensure that a missing main class is indicated in the error message
|
||||
#
|
||||
TestMissingMainClass() {
|
||||
# First create a small jar file with no main
|
||||
printf "public class Foo {}\n" > Foo.java
|
||||
$TESTJAVA/bin/javac Foo.java
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "Error: compilation of Foo.java failed\n"
|
||||
exit 1
|
||||
fi
|
||||
printf "Main-Class: Bar\n" > manifest
|
||||
$TESTJAVA/bin/jar -cvfm some.jar manifest Foo.class
|
||||
if [ ! -f some.jar ]; then
|
||||
printf "Error: did not find some.jar\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# test a non-existence main-class using -jar
|
||||
mess="`$TESTJAVA/bin/java -jar some.jar 2>&1 1>/dev/null`"
|
||||
echo $mess | grep 'Bar' 2>&1 > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "Error: did not find main class missing message\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# test a non-existent main-class using classpath
|
||||
mess="`$TESTJAVA/bin/java -cp some.jar Bar 2>&1 1>/dev/null`"
|
||||
echo $mess | grep 'Bar' 2>&1 > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "Error: did not find main class missing message\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# cleanup
|
||||
rm -f some.jar Foo.* manifest
|
||||
}
|
||||
|
||||
#
|
||||
# Main processing:
|
||||
#
|
||||
@ -117,6 +155,7 @@ TestCP javac -cp
|
||||
TestCP javac -classpath
|
||||
TestXUsage
|
||||
TestHelp
|
||||
TestMissingMainClass
|
||||
|
||||
#
|
||||
# Tests for 6214916
|
||||
|
Loading…
Reference in New Issue
Block a user