< prev index next >
modules/fxml/src/main/java/javafx/fxml/FXMLLoader.java
Print this page
rev 9675 : 8154203: Use StackWalker instead of the now-deprecated sun.reflect.Reflection class
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2016, 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. Oracle designates this
@@ -86,12 +86,10 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.EnumMap;
import java.util.Locale;
import java.util.StringTokenizer;
-import sun.reflect.CallerSensitive;
-import sun.reflect.Reflection;
import sun.reflect.misc.ConstructorUtil;
import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;
/**
@@ -102,10 +100,15 @@
// Indicates permission to get the ClassLoader
private static final RuntimePermission GET_CLASSLOADER_PERMISSION =
new RuntimePermission("getClassLoader");
+ // Instance of StackWalker used to get caller class (must be private)
+ private static final StackWalker walker =
+ AccessController.doPrivileged((PrivilegedAction<StackWalker>) () ->
+ StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE));
+
// Abstract base class for elements
private abstract class Element {
public final Element parent;
public Object value = null;
@@ -2320,16 +2323,15 @@
/**
* Returns the classloader used by this serializer.
* @since JavaFX 2.1
*/
- @CallerSensitive
public ClassLoader getClassLoader() {
if (classLoader == null) {
final SecurityManager sm = System.getSecurityManager();
final Class caller = (sm != null) ?
- Reflection.getCallerClass() :
+ walker.getCallerClass() :
null;
return getDefaultClassLoader(caller);
}
return classLoader;
}
@@ -2402,14 +2404,13 @@
*
* @return
* The loaded object hierarchy.
* @since JavaFX 2.1
*/
- @CallerSensitive
public <T> T load() throws IOException {
return loadImpl((System.getSecurityManager() != null)
- ? Reflection.getCallerClass()
+ ? walker.getCallerClass()
: null);
}
/**
* Loads an object hierarchy from a FXML document.
@@ -2418,14 +2419,13 @@
* An input stream containing the FXML data to load.
*
* @return
* The loaded object hierarchy.
*/
- @CallerSensitive
public <T> T load(InputStream inputStream) throws IOException {
return loadImpl(inputStream, (System.getSecurityManager() != null)
- ? Reflection.getCallerClass()
+ ? walker.getCallerClass()
: null);
}
private Class<?> callerClass;
@@ -3057,15 +3057,14 @@
/**
* Returns the default class loader.
* @since JavaFX 2.1
*/
- @CallerSensitive
public static ClassLoader getDefaultClassLoader() {
final SecurityManager sm = System.getSecurityManager();
final Class caller = (sm != null) ?
- Reflection.getCallerClass() :
+ walker.getCallerClass() :
null;
return getDefaultClassLoader(caller);
}
/**
@@ -3090,14 +3089,13 @@
/**
* Loads an object hierarchy from a FXML document.
*
* @param location
*/
- @CallerSensitive
public static <T> T load(URL location) throws IOException {
return loadImpl(location, (System.getSecurityManager() != null)
- ? Reflection.getCallerClass()
+ ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, Class<?> callerClass)
throws IOException {
@@ -3108,16 +3106,15 @@
* Loads an object hierarchy from a FXML document.
*
* @param location
* @param resources
*/
- @CallerSensitive
public static <T> T load(URL location, ResourceBundle resources)
throws IOException {
return loadImpl(location, resources,
(System.getSecurityManager() != null)
- ? Reflection.getCallerClass()
+ ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
Class<?> callerClass) throws IOException {
@@ -3130,17 +3127,16 @@
*
* @param location
* @param resources
* @param builderFactory
*/
- @CallerSensitive
public static <T> T load(URL location, ResourceBundle resources,
BuilderFactory builderFactory)
throws IOException {
return loadImpl(location, resources, builderFactory,
(System.getSecurityManager() != null)
- ? Reflection.getCallerClass()
+ ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
@@ -3155,18 +3151,17 @@
* @param resources
* @param builderFactory
* @param controllerFactory
* @since JavaFX 2.1
*/
- @CallerSensitive
public static <T> T load(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
Callback<Class<?>, Object> controllerFactory)
throws IOException {
return loadImpl(location, resources, builderFactory, controllerFactory,
(System.getSecurityManager() != null)
- ? Reflection.getCallerClass()
+ ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
@@ -3184,19 +3179,18 @@
* @param builderFactory
* @param controllerFactory
* @param charset
* @since JavaFX 2.1
*/
- @CallerSensitive
public static <T> T load(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
Callback<Class<?>, Object> controllerFactory,
Charset charset) throws IOException {
return loadImpl(location, resources, builderFactory, controllerFactory,
charset,
(System.getSecurityManager() != null)
- ? Reflection.getCallerClass()
+ ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
< prev index next >