8144979: Context.fromClass should catch exception from Class.getClassLoader call

Reviewed-by: attila, mhaupt
This commit is contained in:
Athijegannathan Sundararajan 2015-12-09 16:56:34 +05:30
parent dbcaf8cb02
commit 14fc571c54
20 changed files with 22 additions and 14 deletions

View File

@ -1,6 +1,5 @@
In addition to samples for Nashorn javascript engine, this directory contains This directory contains samples for Dynalink API (http://openjdk.java.net/jeps/276).
samples for Dynalink API (http://openjdk.java.net/jeps/276) as well. Dynalink These samples require a jar file to be built and such jars be placed in the
linker samples require a jar file to be built and such jars be placed in the
classpath of the jjs tool. Linker samples are named with the naming pattern classpath of the jjs tool. Linker samples are named with the naming pattern
"xyz_linker.js". These scripts build dynalink linker jar from java code and exec "xyz_linker.js". These scripts build dynalink linker jar from java code and exec
another jjs process with appropriate classpath set. another jjs process with appropriate classpath set.

View File

@ -44,11 +44,11 @@ var is = Java.to([3, 56, 4, 23], "int[]").stream
print(is.map(function(x) x*x).sum()) print(is.map(function(x) x*x).sum())
// DoubleStream // DoubleStream
var arr = []; var DoubleArray = Java.type("double[]")
for (var i = 0; i < 100; i++) var arr = new DoubleArray(100)
arr.push(Math.random()) for (var i = 0; i < arr.length; i++)
arr[i] = Math.random()
var ds = Java.to(arr, "double[]").stream print(arr.stream.summaryStatistics())
print(ds.summaryStatistics())

View File

@ -37,7 +37,7 @@
$EXEC.throwOnError=true $EXEC.throwOnError=true
// compile ArrayStreamLinkerExporter // compile ArrayStreamLinkerExporter
`javac -cp ../dist/nashorn.jar ArrayStreamLinkerExporter.java` `javac -cp ../../dist/nashorn.jar ArrayStreamLinkerExporter.java`
// make a jar file out of pluggable linker // make a jar file out of pluggable linker
`jar cvf array_stream_linker.jar ArrayStreamLinkerExporter*.class META-INF/` `jar cvf array_stream_linker.jar ArrayStreamLinkerExporter*.class META-INF/`

View File

@ -37,7 +37,7 @@
$EXEC.throwOnError=true $EXEC.throwOnError=true
// compile BufferIndexingLinkerExporter // compile BufferIndexingLinkerExporter
`javac -cp ../dist/nashorn.jar BufferIndexingLinkerExporter.java` `javac -cp ../../dist/nashorn.jar BufferIndexingLinkerExporter.java`
// make a jar file out of pluggable linker // make a jar file out of pluggable linker
`jar cvf buffer_indexing_linker.jar BufferIndexingLinkerExporter*.class META-INF/` `jar cvf buffer_indexing_linker.jar BufferIndexingLinkerExporter*.class META-INF/`

View File

@ -37,7 +37,7 @@
$EXEC.throwOnError=true $EXEC.throwOnError=true
// compile DOMLinkerExporter // compile DOMLinkerExporter
`javac -cp ../dist/nashorn.jar DOMLinkerExporter.java` `javac -cp ../../dist/nashorn.jar DOMLinkerExporter.java`
// make a jar file out of pluggable linker // make a jar file out of pluggable linker
`jar cvf dom_linker.jar DOMLinkerExporter*.class META-INF/` `jar cvf dom_linker.jar DOMLinkerExporter*.class META-INF/`

View File

@ -37,7 +37,7 @@
$EXEC.throwOnError=true $EXEC.throwOnError=true
// compile MissingMethodLinkerExporter // compile MissingMethodLinkerExporter
`javac -cp ../dist/nashorn.jar MissingMethodLinkerExporter.java MissingMethodHandler.java MissingMethodExample.java` `javac -cp ../../dist/nashorn.jar MissingMethodLinkerExporter.java MissingMethodHandler.java MissingMethodExample.java`
// make a jar file out of pluggable linker // make a jar file out of pluggable linker
`jar cvf missing_method_linker.jar MissingMethod*.class META-INF/` `jar cvf missing_method_linker.jar MissingMethod*.class META-INF/`

View File

@ -37,7 +37,7 @@
$EXEC.throwOnError=true $EXEC.throwOnError=true
// compile UnderscoreNameLinkerExporter // compile UnderscoreNameLinkerExporter
`javac -cp ../dist/nashorn.jar UnderscoreNameLinkerExporter.java` `javac -cp ../../dist/nashorn.jar UnderscoreNameLinkerExporter.java`
// make a jar file out of pluggable linker // make a jar file out of pluggable linker
`jar cvf underscore_linker.jar UnderscoreNameLinkerExporter*.class META-INF/` `jar cvf underscore_linker.jar UnderscoreNameLinkerExporter*.class META-INF/`

View File

@ -1300,7 +1300,16 @@ public final class Context {
* @return context * @return context
*/ */
static Context fromClass(final Class<?> clazz) { static Context fromClass(final Class<?> clazz) {
final ClassLoader loader = clazz.getClassLoader(); ClassLoader loader = null;
try {
loader = clazz.getClassLoader();
} catch (SecurityException ignored) {
// This could fail because of anonymous classes being used.
// Accessing loader of anonymous class fails (for extension
// loader class too?). In any case, for us fetching Context
// from class loader is just an optimization. We can always
// get Context from thread local storage (below).
}
if (loader instanceof ScriptLoader) { if (loader instanceof ScriptLoader) {
return ((ScriptLoader)loader).getContext(); return ((ScriptLoader)loader).getContext();