@StubMethod public static ClassMirror getCallerClassMirror(int depth) { // Filter out any non-holographic frames int nativeDepth = 1; Class<?> klass = sun.reflect.Reflection.getCallerClass(nativeDepth); while (klass != null) { ClassLoader loader = klass.getClassLoader(); if (loader instanceof HologramClassLoader) { if (depth == 0) { HologramClassLoader hologramClassLoader = (HologramClassLoader) klass.getClassLoader(); String className = HologramClassGenerator.getOriginalBinaryClassName(klass.getName()); return hologramClassLoader.loadOriginalClassMirror(className); } depth--; } nativeDepth++; klass = sun.reflect.Reflection.getCallerClass(nativeDepth); } // Off the top of the holographic stack, so refer to the original stack. ThreadMirror currentThread = ThreadHolograph.currentThreadMirror(); List<FrameMirror> stack = currentThread.getStackTrace(); int frameIndex = stack.size() - 1 - depth; if (frameIndex < 0) { return null; } FrameMirror frame = stack.get(frameIndex); return frame.declaringClass(); }
protected boolean hasGetProxySelector() { if (JavaDetector.isJDK7()) { Class<?> callerClass8 = Reflection.getCallerClass(8); String className8 = callerClass8.getName(); if (className8.startsWith(_CLASS_NAME_SOCKS_SOCKET_IMPL)) { logGetProxySelector(callerClass8, 8); return true; } } else { Class<?> callerClass7 = Reflection.getCallerClass(7); String className7 = callerClass7.getName(); if (className7.startsWith(_CLASS_NAME_SOCKS_SOCKET_IMPL)) { logGetProxySelector(callerClass7, 7); return true; } } return false; }
@Nullable public static Image loadFromResource(@NonNls String s) { int stackFrameCount = 2; Class callerClass = Reflection.getCallerClass(stackFrameCount); while (callerClass != null && callerClass.getClassLoader() == null) { // looks like a system class callerClass = Reflection.getCallerClass(++stackFrameCount); } if (callerClass == null) { callerClass = Reflection.getCallerClass(1); } return loadFromResource(s, callerClass); }
/** * Invokes the underlying method represented by this {@code Method} object, on the specified * object with the specified parameters. Individual parameters are automatically unwrapped to * match primitive formal parameters, and both primitive and reference parameters are subject to * method invocation conversions as necessary. * * <p>If the underlying method is static, then the specified {@code obj} argument is ignored. It * may be null. * * <p>If the number of formal parameters required by the underlying method is 0, the supplied * {@code args} array may be of length 0 or null. * * <p>If the underlying method is an instance method, it is invoked using dynamic method lookup as * documented in The Java Language Specification, Second Edition, section 15.12.4.4; in * particular, overriding based on the runtime type of the target object will occur. * * <p>If the underlying method is static, the class that declared the method is initialized if it * has not already been initialized. * * <p>If the method completes normally, the value it returns is returned to the caller of invoke; * if the value has a primitive type, it is first appropriately wrapped in an object. However, if * the value has the type of an array of a primitive type, the elements of the array are * <i>not</i> wrapped in objects; in other words, an array of primitive type is returned. If the * underlying method return type is void, the invocation returns null. * * @param obj the object the underlying method is invoked from * @param args the arguments used for the method call * @return the result of dispatching the method represented by this object on {@code obj} with * parameters {@code args} * @exception IllegalAccessException if this {@code Method} object is enforcing Java language * access control and the underlying method is inaccessible. * @exception IllegalArgumentException if the method is an instance method and the specified * object argument is not an instance of the class or interface declaring the underlying * method (or of a subclass or implementor thereof); if the number of actual and formal * parameters differ; if an unwrapping conversion for primitive arguments fails; or if, after * possible unwrapping, a parameter value cannot be converted to the corresponding formal * parameter type by a method invocation conversion. * @exception InvocationTargetException if the underlying method throws an exception. * @exception NullPointerException if the specified object is null and the method is an instance * method. * @exception ExceptionInInitializerError if the initialization provoked by this method fails. */ public Object invoke(Object obj, Object... args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (!override) { if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) { Class<?> caller = Reflection.getCallerClass(1); checkAccess(caller, clazz, obj, modifiers); } } MethodAccessor ma = methodAccessor; // read volatile if (ma == null) { ma = acquireMethodAccessor(); } return ma.invoke(obj, args); }
/** * Initialise les composants du conteneur sémantique une fois les URI des ontologies dispatchées * par OwlDistributionInitializer. */ public void semInit() throws ExceptionInInitializerError { if (isInitialized()) { /** Initialisation de l'ontologie locale. Cette ontologie n'est plus modifiée ensuite. */ // Initialisation du manager de l'ontologie locale. N'est utilisé qu'ici. OWLOntologyManager localOntoManager = OWLManager.createOWLOntologyManager(); OWLOntologyIRIMapper localOntoMapper = new SimpleIRIMapper(getOntologyIri(), getPhysicalIri()); localOntoManager.addIRIMapper(localOntoMapper); // Initialisation de l'ontologie try { // On crée l'ontologie locale. this.localOntology = localOntoManager.loadOntology(getPhysicalIri()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } // System.out.println("localOntology : " + localOntology + " ; pyhsicalIri : " + // getPhysicalIri().toString()); /** * Initialisation de l'ontologie du reasoner, qui contiendra l'ontologie locale plus d'autres * axiomes éventuels. On crée l'instance, qu'on rattache à un manager et un reasoner * accessibles par des getters. L'instance reste la même, mais le contenu change. */ // Initialisation du manager de l'ontologie du reasoner this.manager = OWLManager.createOWLOntologyManager(); // On crée une deuxième ontologie. try { IRI ontoName = IRI.create(this.nameSpace); OWLOntologyID ontoId = new OWLOntologyID(ontoName); this.reasoningOntology = this.manager.createOntology(ontoId); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } // Initialisation du reasoner PelletReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance(); PelletOptions.USE_INCREMENTAL_CONSISTENCY = true; PelletOptions.USE_COMPLETION_QUEUE = true; // PelletReasoner reasoner = reasonerFactory.createReasoner(reasoningOntology); PelletReasoner reasoner = reasonerFactory.createNonBufferingReasoner(reasoningOntology); // add the reasoner as an ontology change listener this.manager.addOntologyChangeListener(reasoner); reasoner.precomputeInferences(InferenceType.CLASS_HIERARCHY); /* reasoner.precomputeInferences(InferenceType.CLASS_ASSERTIONS); reasoner.precomputeInferences(InferenceType.DATA_PROPERTY_HIERARCHY); reasoner.precomputeInferences(InferenceType.DISJOINT_CLASSES); reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_HIERARCHY); reasoner.precomputeInferences(InferenceType.SAME_INDIVIDUAL); */ this.reasoner = reasoner; } else throw new ExceptionInInitializerError( "Paramètres de l'ontologie non initialisés ; ontoParamsInit = " + Reflection.getCallerClass(2)); // initOntoReasoner(); }
/** * Attempts to locate a driver that understands the given URL. The <code>DriverManager</code> * attempts to select an appropriate driver from the set of registered JDBC drivers. * * @param url a database URL of the form <code>jdbc:<em>subprotocol</em>:<em>subname</em></code> * @return a <code>Driver</code> object representing a driver that can connect to the given URL * @exception SQLException if a database access error occurs */ @CallerSensitive public static Driver getDriver(String url) throws SQLException { println("DriverManager.getDriver(\"" + url + "\")"); Class<?> callerClass = Reflection.getCallerClass(); // Walk through the loaded registeredDrivers attempting to locate someone // who understands the given URL. for (DriverInfo aDriver : registeredDrivers) { // If the caller does not have permission to load the driver then // skip it. if (isDriverAllowed(aDriver.driver, callerClass)) { try { if (aDriver.driver.acceptsURL(url)) { // Success! println("getDriver returning " + aDriver.driver.getClass().getName()); return (aDriver.driver); } } catch (SQLException sqe) { // Drop through and try the next driver. } } else { println(" skipping: " + aDriver.driver.getClass().getName()); } } println("getDriver: no suitable driver"); throw new SQLException("No suitable driver", "08001"); }
/** * Removes the specified driver from the {@code DriverManager}'s list of registered drivers. * * <p>If a {@code null} value is specified for the driver to be removed, then no action is taken. * * <p>If a security manager exists and its {@code checkPermission} denies permission, then a * {@code SecurityException} will be thrown. * * <p>If the specified driver is not found in the list of registered drivers, then no action is * taken. If the driver was found, it will be removed from the list of registered drivers. * * <p>If a {@code DriverAction} instance was specified when the JDBC driver was registered, its * deregister method will be called prior to the driver being removed from the list of registered * drivers. * * @param driver the JDBC Driver to remove * @exception SQLException if a database access error occurs * @throws SecurityException if a security manager exists and its {@code checkPermission} method * denies permission to deregister a driver. * @see SecurityManager#checkPermission */ @CallerSensitive public static synchronized void deregisterDriver(Driver driver) throws SQLException { if (driver == null) { return; } SecurityManager sec = System.getSecurityManager(); if (sec != null) { sec.checkPermission(DEREGISTER_DRIVER_PERMISSION); } println("DriverManager.deregisterDriver: " + driver); DriverInfo aDriver = new DriverInfo(driver, null); if (registeredDrivers.contains(aDriver)) { if (isDriverAllowed(driver, Reflection.getCallerClass())) { DriverInfo di = registeredDrivers.get(registeredDrivers.indexOf(aDriver)); // If a DriverAction was specified, Call it to notify the // driver that it has been deregistered if (di.action() != null) { di.action().deregister(); } registeredDrivers.remove(aDriver); } else { // If the caller does not have permission to load the driver then // throw a SecurityException. throw new SecurityException(); } } else { println(" couldn't find driver to unload"); } }
protected boolean hasReflect(Permission permission) { int stackIndex = getStackIndex(13, 12); Class<?> callerClass = Reflection.getCallerClass(stackIndex); if (isTrustedCaller(callerClass, permission)) { return true; } return false; }
protected boolean hasSetContextClassLoader(Permission permission) { int stackIndex = getStackIndex(11, 10); Class<?> callerClass = Reflection.getCallerClass(stackIndex); if (isTrustedCaller(callerClass, permission)) { return true; } return false; }
protected boolean hasWriteFileDescriptor(Permission permission) { int stackIndex = getStackIndex(12, 11); Class<?> callerClass = Reflection.getCallerClass(stackIndex); if (isTrustedCaller(callerClass, permission)) { return true; } return false; }
protected boolean hasCreateSecurityManager(Permission permission) { int stackIndex = getStackIndex(11, 10); Class<?> callerClass = Reflection.getCallerClass(stackIndex); if (isTrustedCaller(callerClass, permission)) { return true; } return false; }
/* * Reflection.ensureMemberAccess is overly-restrictive * due to a bug. We awkwardly work around it for now. */ public static void ensureMemberAccess( Class currentClass, Class memberClass, Object target, int modifiers) throws IllegalAccessException { if (target == null && Modifier.isProtected(modifiers)) { int mods = modifiers; mods = mods & (~Modifier.PROTECTED); mods = mods | Modifier.PUBLIC; /* * See if we fail because of class modifiers */ Reflection.ensureMemberAccess(currentClass, memberClass, target, mods); try { /* * We're still here so class access was ok. * Now try with default field access. */ mods = mods & (~Modifier.PUBLIC); Reflection.ensureMemberAccess(currentClass, memberClass, target, mods); /* * We're still here so access is ok without * checking for protected. */ return; } catch (IllegalAccessException e) { /* * Access failed but we're 'protected' so * if the test below succeeds then we're ok. */ if (isSubclassOf(currentClass, memberClass)) { return; } else { throw e; } } } else { Reflection.ensureMemberAccess(currentClass, memberClass, target, modifiers); } }
/** * Attempts to establish a connection to the given database URL. The <code>DriverManager</code> * attempts to select an appropriate driver from the set of registered JDBC drivers. * * <p><B>Note:</B> If the {@code user} or {@code password} property are also specified as part of * the {@code url}, it is implementation-defined as to which value will take precedence. For * maximum portability, an application should only specify a property once. * * @param url a database url of the form <code>jdbc:<em>subprotocol</em>:<em>subname</em></code> * @param user the database user on whose behalf the connection is being made * @param password the user's password * @return a connection to the URL * @exception SQLException if a database access error occurs or the url is {@code null} * @throws SQLTimeoutException when the driver has determined that the timeout value specified by * the {@code setLoginTimeout} method has been exceeded and has at least tried to cancel the * current database connection attempt */ @CallerSensitive public static Connection getConnection(String url, String user, String password) throws SQLException { java.util.Properties info = new java.util.Properties(); if (user != null) { info.put("user", user); } if (password != null) { info.put("password", password); } return (getConnection(url, info, Reflection.getCallerClass())); }
@CallerSensitive public <T> Prop<T> type() { Prop on = this; if (!isCannon()) { Prop<T> already = (Prop<T>) findCannon(); if (already == null) { toCannon(); on.setCannon(); } else { on = already; } } Class c = sun.reflect.Reflection.getCallerClass(2); on.definedInClass = c; Field f = null; try { f = c.getField(name); } catch (NoSuchFieldException e) { try { f = c.getField("_" + name); } catch (NoSuchFieldException e3) { if (name.startsWith("_")) try { f = c.getField(name.substring(1)); } catch (NoSuchFieldException e1) { if (name.startsWith("__")) try { f = c.getField(name.substring(1)); } catch (NoSuchFieldException e2) { } } } } if (f == null) throw new IllegalStateException( " cannot type a Dict.Prop<T> that we can't find. Name is :" + name + " class is :" + c); on.typeInformation = Conversions.linearize(f.getGenericType()); on.typeInformation.remove(0); return (Prop<T>) on; }
private static String getCalling(boolean methodName) { int depth = 4; if (methodName) { StackTraceElement e[] = Thread.currentThread().getStackTrace(); if ((e != null) && (e.length >= depth)) { StackTraceElement s = e[depth]; if (s != null) { String finalValue = s.getClassName().substring((s.getClassName().lastIndexOf(".") + 1)); finalValue = finalValue + "." + s.getMethodName() + "():" + s.getLineNumber(); return finalValue; } } return null; } else { return sun.reflect.Reflection.getCallerClass(depth + 1).getSimpleName(); } }
/** * Retrieves an Enumeration with all of the currently loaded JDBC drivers to which the current * caller has access. * * <p><B>Note:</B> The classname of a driver can be found using <CODE>d.getClass().getName() * </CODE> * * @return the list of JDBC Drivers loaded by the caller's class loader */ @CallerSensitive public static java.util.Enumeration<Driver> getDrivers() { java.util.Vector<Driver> result = new java.util.Vector<>(); Class<?> callerClass = Reflection.getCallerClass(); // Walk through the loaded registeredDrivers. for (DriverInfo aDriver : registeredDrivers) { // If the caller does not have permission to load the driver then // skip it. if (isDriverAllowed(aDriver.driver, callerClass)) { result.addElement(aDriver.driver); } else { println(" skipping: " + aDriver.getClass().getName()); } } return (result.elements()); }
protected boolean hasGetEnv(String name, Permission permission) { for (Pattern environmentVariablePattern : _environmentVariablePatterns) { Matcher matcher = environmentVariablePattern.matcher(name); if (matcher.matches()) { return true; } } int stackIndex = getStackIndex(11, 10); Class<?> callerClass = Reflection.getCallerClass(stackIndex); if (isTrustedCaller(callerClass, permission)) { return true; } return false; }
/** * Creates and returns an updater for objects with the given field. The Class argument is needed * to check that reflective types and generic types match. * * @param tclass the class of the objects holding the field * @param fieldName the name of the field to be updated. * @return the updater * @throws IllegalArgumentException if the field is not a volatile long type. * @throws RuntimeException with a nested reflection-based exception if the class does not hold * field or is the wrong type. */ @CallerSensitive public static <U> AtomicLongFieldUpdater<U> newUpdater(Class<U> tclass, String fieldName) { Class<?> caller = Reflection.getCallerClass(); if (AtomicLong.VM_SUPPORTS_LONG_CAS) return new CASUpdater<U>(tclass, fieldName, caller); else return new LockedUpdater<U>(tclass, fieldName, caller); }
public ClassLoader missingCallerSensitiveAnnotation() { Class<?> c = sun.reflect.Reflection.getCallerClass(); return c.getClassLoader(); }
@sun.reflect.CallerSensitive public ClassLoader getCallerLoader() { Class<?> c = sun.reflect.Reflection.getCallerClass(); return c.getClassLoader(); }
/** * Creates and returns an updater for objects with the given field. The Class arguments are needed * to check that reflective types and generic types match. * * @param tclass the class of the objects holding the field. * @param vclass the class of the field * @param fieldName the name of the field to be updated. * @return the updater * @throws IllegalArgumentException if the field is not a volatile reference type. * @throws RuntimeException with a nested reflection-based exception if the class does not hold * field or is the wrong type. */ @CallerSensitive public static <U, W> AtomicReferenceFieldUpdater<U, W> newUpdater( Class<U> tclass, Class<W> vclass, String fieldName) { return new AtomicReferenceFieldUpdaterImpl<U, W>( tclass, vclass, fieldName, Reflection.getCallerClass()); }
/** * Attempts to establish a connection to the given database URL. The <code>DriverManager</code> * attempts to select an appropriate driver from the set of registered JDBC drivers. * * @param url a database url of the form <code> jdbc:<em>subprotocol</em>:<em>subname</em></code> * @return a connection to the URL * @exception SQLException if a database access error occurs or the url is {@code null} * @throws SQLTimeoutException when the driver has determined that the timeout value specified by * the {@code setLoginTimeout} method has been exceeded and has at least tried to cancel the * current database connection attempt */ @CallerSensitive public static Connection getConnection(String url) throws SQLException { java.util.Properties info = new java.util.Properties(); return (getConnection(url, info, Reflection.getCallerClass())); }
/* returns the class of the caller. */ static Class<?> getCallerClass() { // NOTE use of more generic Reflection.getCallerClass() return Reflection.getCallerClass(3); }