8144979: Context.fromClass should catch exception from Class.getClassLoader call
Reviewed-by: attila, mhaupt
This commit is contained in:
parent
dbcaf8cb02
commit
14fc571c54
@ -1,6 +1,5 @@
|
||||
In addition to samples for Nashorn javascript engine, this directory contains
|
||||
samples for Dynalink API (http://openjdk.java.net/jeps/276) as well. Dynalink
|
||||
linker samples require a jar file to be built and such jars be placed in the
|
||||
This directory contains samples for Dynalink API (http://openjdk.java.net/jeps/276).
|
||||
These 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
|
||||
"xyz_linker.js". These scripts build dynalink linker jar from java code and exec
|
||||
another jjs process with appropriate classpath set.
|
@ -44,11 +44,11 @@ var is = Java.to([3, 56, 4, 23], "int[]").stream
|
||||
print(is.map(function(x) x*x).sum())
|
||||
|
||||
// DoubleStream
|
||||
var arr = [];
|
||||
for (var i = 0; i < 100; i++)
|
||||
arr.push(Math.random())
|
||||
var DoubleArray = Java.type("double[]")
|
||||
var arr = new DoubleArray(100)
|
||||
for (var i = 0; i < arr.length; i++)
|
||||
arr[i] = Math.random()
|
||||
|
||||
var ds = Java.to(arr, "double[]").stream
|
||||
print(ds.summaryStatistics())
|
||||
print(arr.stream.summaryStatistics())
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
$EXEC.throwOnError=true
|
||||
|
||||
// compile ArrayStreamLinkerExporter
|
||||
`javac -cp ../dist/nashorn.jar ArrayStreamLinkerExporter.java`
|
||||
`javac -cp ../../dist/nashorn.jar ArrayStreamLinkerExporter.java`
|
||||
|
||||
// make a jar file out of pluggable linker
|
||||
`jar cvf array_stream_linker.jar ArrayStreamLinkerExporter*.class META-INF/`
|
@ -37,7 +37,7 @@
|
||||
$EXEC.throwOnError=true
|
||||
|
||||
// compile BufferIndexingLinkerExporter
|
||||
`javac -cp ../dist/nashorn.jar BufferIndexingLinkerExporter.java`
|
||||
`javac -cp ../../dist/nashorn.jar BufferIndexingLinkerExporter.java`
|
||||
|
||||
// make a jar file out of pluggable linker
|
||||
`jar cvf buffer_indexing_linker.jar BufferIndexingLinkerExporter*.class META-INF/`
|
@ -37,7 +37,7 @@
|
||||
$EXEC.throwOnError=true
|
||||
|
||||
// compile DOMLinkerExporter
|
||||
`javac -cp ../dist/nashorn.jar DOMLinkerExporter.java`
|
||||
`javac -cp ../../dist/nashorn.jar DOMLinkerExporter.java`
|
||||
|
||||
// make a jar file out of pluggable linker
|
||||
`jar cvf dom_linker.jar DOMLinkerExporter*.class META-INF/`
|
@ -37,7 +37,7 @@
|
||||
$EXEC.throwOnError=true
|
||||
|
||||
// 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
|
||||
`jar cvf missing_method_linker.jar MissingMethod*.class META-INF/`
|
@ -37,7 +37,7 @@
|
||||
$EXEC.throwOnError=true
|
||||
|
||||
// compile UnderscoreNameLinkerExporter
|
||||
`javac -cp ../dist/nashorn.jar UnderscoreNameLinkerExporter.java`
|
||||
`javac -cp ../../dist/nashorn.jar UnderscoreNameLinkerExporter.java`
|
||||
|
||||
// make a jar file out of pluggable linker
|
||||
`jar cvf underscore_linker.jar UnderscoreNameLinkerExporter*.class META-INF/`
|
@ -1300,7 +1300,16 @@ public final class Context {
|
||||
* @return context
|
||||
*/
|
||||
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) {
|
||||
return ((ScriptLoader)loader).getContext();
|
||||
|
Loading…
Reference in New Issue
Block a user