< 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 ****
/*
! * Copyright (c) 2010, 2015, 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
--- 1,7 ----
/*
! * 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,97 ****
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;
/**
--- 86,95 ----
*** 102,111 ****
--- 100,114 ----
// 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,2335 ****
/**
* 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() :
null;
return getDefaultClassLoader(caller);
}
return classLoader;
}
--- 2323,2337 ----
/**
* Returns the classloader used by this serializer.
* @since JavaFX 2.1
*/
public ClassLoader getClassLoader() {
if (classLoader == null) {
final SecurityManager sm = System.getSecurityManager();
final Class caller = (sm != null) ?
! walker.getCallerClass() :
null;
return getDefaultClassLoader(caller);
}
return classLoader;
}
*** 2402,2415 ****
*
* @return
* The loaded object hierarchy.
* @since JavaFX 2.1
*/
- @CallerSensitive
public <T> T load() throws IOException {
return loadImpl((System.getSecurityManager() != null)
! ? Reflection.getCallerClass()
: null);
}
/**
* Loads an object hierarchy from a FXML document.
--- 2404,2416 ----
*
* @return
* The loaded object hierarchy.
* @since JavaFX 2.1
*/
public <T> T load() throws IOException {
return loadImpl((System.getSecurityManager() != null)
! ? walker.getCallerClass()
: null);
}
/**
* Loads an object hierarchy from a FXML document.
*** 2418,2431 ****
* 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()
: null);
}
private Class<?> callerClass;
--- 2419,2431 ----
* An input stream containing the FXML data to load.
*
* @return
* The loaded object hierarchy.
*/
public <T> T load(InputStream inputStream) throws IOException {
return loadImpl(inputStream, (System.getSecurityManager() != null)
! ? walker.getCallerClass()
: null);
}
private Class<?> callerClass;
*** 3057,3071 ****
/**
* 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() :
null;
return getDefaultClassLoader(caller);
}
/**
--- 3057,3070 ----
/**
* Returns the default class loader.
* @since JavaFX 2.1
*/
public static ClassLoader getDefaultClassLoader() {
final SecurityManager sm = System.getSecurityManager();
final Class caller = (sm != null) ?
! walker.getCallerClass() :
null;
return getDefaultClassLoader(caller);
}
/**
*** 3090,3103 ****
/**
* 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()
: null);
}
private static <T> T loadImpl(URL location, Class<?> callerClass)
throws IOException {
--- 3089,3101 ----
/**
* Loads an object hierarchy from a FXML document.
*
* @param location
*/
public static <T> T load(URL location) throws IOException {
return loadImpl(location, (System.getSecurityManager() != null)
! ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, Class<?> callerClass)
throws IOException {
*** 3108,3123 ****
* 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()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
Class<?> callerClass) throws IOException {
--- 3106,3120 ----
* Loads an object hierarchy from a FXML document.
*
* @param location
* @param resources
*/
public static <T> T load(URL location, ResourceBundle resources)
throws IOException {
return loadImpl(location, resources,
(System.getSecurityManager() != null)
! ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
Class<?> callerClass) throws IOException {
*** 3130,3146 ****
*
* @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()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
--- 3127,3142 ----
*
* @param location
* @param resources
* @param builderFactory
*/
public static <T> T load(URL location, ResourceBundle resources,
BuilderFactory builderFactory)
throws IOException {
return loadImpl(location, resources, builderFactory,
(System.getSecurityManager() != null)
! ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
*** 3155,3172 ****
* @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()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
--- 3151,3167 ----
* @param resources
* @param builderFactory
* @param controllerFactory
* @since JavaFX 2.1
*/
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)
! ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
*** 3184,3202 ****
* @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()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
--- 3179,3196 ----
* @param builderFactory
* @param controllerFactory
* @param charset
* @since JavaFX 2.1
*/
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)
! ? walker.getCallerClass()
: null);
}
private static <T> T loadImpl(URL location, ResourceBundle resources,
BuilderFactory builderFactory,
< prev index next >