commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1567781 [3/5] - in /commons/proper/weaver/trunk: ant/lib/src/main/java/org/apache/commons/weaver/ant/ dist/ dist/src/assembly/ example/src/main/java/org/apache/commons/weaver/privilizer/example/ example/src/test/java/org/apache/commons/wea...
Date Wed, 12 Feb 2014 22:40:08 GMT
Modified: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/ActionGenerator.java
URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/ActionGenerator.java?rev=1567781&r1=1567780&r2=1567781&view=diff
==============================================================================
--- commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/ActionGenerator.java (original)
+++ commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/ActionGenerator.java Wed Feb 12 22:40:06 2014
@@ -1,232 +1,232 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.commons.weaver.privilizer;
-
-import java.lang.reflect.Modifier;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedExceptionAction;
-import java.util.Map;
-
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.Validate;
-import org.apache.commons.lang3.builder.Builder;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Label;
-import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
-import org.objectweb.asm.commons.GeneratorAdapter;
-import org.objectweb.asm.commons.Method;
-import org.objectweb.asm.signature.SignatureReader;
-import org.objectweb.asm.signature.SignatureVisitor;
-import org.objectweb.asm.signature.SignatureWriter;
-
-/**
- * Generates the Privileged[Exception?]Action class to privilize a given Method.
- */
-class ActionGenerator extends Privilizer.WriteClass implements Builder<Type> {
-    final PrivilizingVisitor owner;
-    final Method m;
-    final boolean exc;
-    final Type[] exceptions;
-    final String simpleName;
-    final Type action;
-    final Method impl;
-    final int index;
-    final boolean implIsStatic;
-    final Method helper;
-    final Type result;
-    final Field[] fields;
-    private final Type actionInterface;
-
-    /**
-     * Create a new {@link ActionGenerator}.
-     * @param access modifier
-     * @param m {@link Method} to implement
-     * @param exceptions thrown
-     * @param owner of the action class
-     */
-    ActionGenerator(final int access, final Method m, final String[] exceptions, PrivilizingVisitor owner) {
-        owner.privilizer().super(new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES));
-        this.m = m;
-        this.exc = ArrayUtils.isNotEmpty(exceptions);
-        this.exceptions = exc ? new Type[] { Type.getType(Exception.class) } : null;
-        this.owner = owner;
-        this.simpleName = generateName(m);
-        this.action = Type.getObjectType(owner.className + '$' + simpleName);
-
-        int privilegedAccessIndex = -1;
-        String implName = null;
-        for (Map.Entry<Method, String> e : owner.privilegedMethods.entrySet()) {
-            privilegedAccessIndex++;
-            if (e.getKey().equals(m)) {
-                implName = e.getValue();
-                break;
-            }
-        }
-        Validate.validState(implName != null);
-
-        this.index = privilegedAccessIndex;
-
-        this.impl = new Method(implName, m.getDescriptor());
-        this.implIsStatic = Modifier.isStatic(access);
-        final Type[] args = implIsStatic ? m.getArgumentTypes() : ArrayUtils.add(m.getArgumentTypes(), 0, owner.target);
-        this.helper = new Method(privilizer().generateName("access$" + index), m.getReturnType(), args);
-        this.result = privilizer().wrap(m.getReturnType());
-        this.fields = fields(args);
-        this.actionInterface = Type.getType(exc ? PrivilegedExceptionAction.class : PrivilegedAction.class);
-    }
-
-    private static String generateName(Method m) {
-        final StringBuilder b = new StringBuilder(m.getName());
-        if (m.getArgumentTypes().length > 0) {
-            b.append("$$");
-            for (Type arg : m.getArgumentTypes()) {
-                b.append(arg.getDescriptor().replace("[", "arrayOf").replace('/', '_').replace(';', '$'));
-            }
-        }
-        return b.append("_ACTION").toString();
-    }
-
-    private static Field[] fields(Type[] args) {
-        final Field[] result = new Field[args.length];
-
-        for (int i = 0; i < args.length; i++) {
-            final String name = new StringBuilder("f").append(i + 1).toString();
-            result[i] = new Field(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, name, args[i]);
-        }
-        return result;
-    }
-
-    @Override
-    public Type build() {
-        generateHelper();
-        begin();
-        init();
-        impl();
-        visitEnd();
-        owner.privilizer().env.debug("Generated %s implementation %s to call %s#%s", actionInterface.getClassName(),
-            action.getClassName(), owner.target.getClassName(), helper);
-        return action;
-    }
-
-    /**
-     * We must add special methods for inner classes to invoke their owners' methods, according to the scheme "access$n"
-     * where n is the index into this (ordered) map. Additionally we will prefix the whole thing like we usually do
-     * (__privileged_):
-     */
-    private void generateHelper() {
-        owner.privilizer().env.debug("Generating static helper method %s.%s to call %s", owner.target.getClassName(),
-            helper, impl);
-        final GeneratorAdapter mg =
-            new GeneratorAdapter(Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, helper, null, exceptions, owner);
-
-        mg.visitCode();
-        mg.loadArgs();
-        if (implIsStatic) {
-            mg.invokeStatic(owner.target, impl);
-        } else {
-            mg.invokeVirtual(owner.target, impl);
-        }
-        mg.returnValue();
-        mg.endMethod();
-    }
-
-    private void begin() {
-        owner.visitInnerClass(action.getInternalName(), owner.className, simpleName, Opcodes.ACC_PRIVATE
-            | Opcodes.ACC_STATIC);
-
-        final SignatureWriter type = new SignatureWriter();
-        final SignatureVisitor actionImplemented = type.visitInterface();
-        actionImplemented.visitClassType(actionInterface.getInternalName());
-        final SignatureVisitor visitTypeArgument = actionImplemented.visitTypeArgument('=');
-        final SignatureReader result = new SignatureReader(privilizer().wrap(m.getReturnType()).getDescriptor());
-        result.accept(visitTypeArgument);
-        actionImplemented.visitEnd();
-
-        final String signature = type.toString();
-
-        visit(Opcodes.V1_5, Opcodes.ACC_SUPER | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_FINAL, action.getInternalName(),
-            signature, Type.getType(Object.class).getInternalName(),
-            new String[] { actionInterface.getInternalName() });
-    }
-
-    /**
-     * Add fields and generate constructor.
-     */
-    private void init() {
-        for (Field field : fields) {
-            visitField(field.access, field.name, field.type.getDescriptor(), null, null).visitEnd();
-        }
-        final Method init = new Method("<init>", Type.VOID_TYPE, helper.getArgumentTypes());
-
-        final GeneratorAdapter mg =
-            new GeneratorAdapter(0, init, null, Privilizer.EMPTY_TYPE_ARRAY, this);
-
-        mg.visitCode();
-        final Label begin = mg.mark();
-
-        // invoke super constructor
-        mg.loadThis();
-        mg.invokeConstructor(Type.getType(Object.class), Method.getMethod("void <init> ()"));
-        // assign remaining fields
-
-        int arg = 0;
-        for (Field field : fields) {
-            mg.loadThis();
-            mg.loadArg(arg++);
-            mg.putField(action, field.name, field.type);
-        }
-
-        mg.returnValue();
-        final Label end = mg.mark();
-
-        // declare local vars
-        mg.visitLocalVariable("this", action.getDescriptor(), null, begin, end, 0);
-        arg = 1;
-        for (Field field : fields) {
-            mg.visitLocalVariable("arg" + arg, field.type.getDescriptor(), null, begin, end, arg++);
-        }
-        mg.endMethod();
-    }
-
-    /**
-     * Generate impl method.
-     */
-    private void impl() {
-        final Method run = Method.getMethod("Object run()");
-
-        final GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, run, null, exceptions, this);
-
-        for (Field field : fields) {
-            mg.loadThis();
-            mg.getField(action, field.name, field.type);
-        }
-
-        mg.invokeStatic(owner.target, helper);
-
-        if (m.getReturnType().getSort() < Type.ARRAY) {
-            mg.valueOf(m.getReturnType());
-        }
-
-        mg.returnValue();
-
-        mg.endMethod();
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.weaver.privilizer;
+
+import java.lang.reflect.Modifier;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
+import java.util.Map;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+import org.apache.commons.lang3.builder.Builder;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.commons.GeneratorAdapter;
+import org.objectweb.asm.commons.Method;
+import org.objectweb.asm.signature.SignatureReader;
+import org.objectweb.asm.signature.SignatureVisitor;
+import org.objectweb.asm.signature.SignatureWriter;
+
+/**
+ * Generates the Privileged[Exception?]Action class to privilize a given Method.
+ */
+class ActionGenerator extends Privilizer.WriteClass implements Builder<Type> {
+    final PrivilizingVisitor owner;
+    final Method m;
+    final boolean exc;
+    final Type[] exceptions;
+    final String simpleName;
+    final Type action;
+    final Method impl;
+    final int index;
+    final boolean implIsStatic;
+    final Method helper;
+    final Type result;
+    final Field[] fields;
+    private final Type actionInterface;
+
+    /**
+     * Create a new {@link ActionGenerator}.
+     * @param access modifier
+     * @param m {@link Method} to implement
+     * @param exceptions thrown
+     * @param owner of the action class
+     */
+    ActionGenerator(final int access, final Method m, final String[] exceptions, PrivilizingVisitor owner) {
+        owner.privilizer().super(new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES));
+        this.m = m;
+        this.exc = ArrayUtils.isNotEmpty(exceptions);
+        this.exceptions = exc ? new Type[] { Type.getType(Exception.class) } : null;
+        this.owner = owner;
+        this.simpleName = generateName(m);
+        this.action = Type.getObjectType(owner.className + '$' + simpleName);
+
+        int privilegedAccessIndex = -1;
+        String implName = null;
+        for (Map.Entry<Method, String> e : owner.privilegedMethods.entrySet()) {
+            privilegedAccessIndex++;
+            if (e.getKey().equals(m)) {
+                implName = e.getValue();
+                break;
+            }
+        }
+        Validate.validState(implName != null);
+
+        this.index = privilegedAccessIndex;
+
+        this.impl = new Method(implName, m.getDescriptor());
+        this.implIsStatic = Modifier.isStatic(access);
+        final Type[] args = implIsStatic ? m.getArgumentTypes() : ArrayUtils.add(m.getArgumentTypes(), 0, owner.target);
+        this.helper = new Method(privilizer().generateName("access$" + index), m.getReturnType(), args);
+        this.result = privilizer().wrap(m.getReturnType());
+        this.fields = fields(args);
+        this.actionInterface = Type.getType(exc ? PrivilegedExceptionAction.class : PrivilegedAction.class);
+    }
+
+    private static String generateName(Method m) {
+        final StringBuilder b = new StringBuilder(m.getName());
+        if (m.getArgumentTypes().length > 0) {
+            b.append("$$");
+            for (Type arg : m.getArgumentTypes()) {
+                b.append(arg.getDescriptor().replace("[", "arrayOf").replace('/', '_').replace(';', '$'));
+            }
+        }
+        return b.append("_ACTION").toString();
+    }
+
+    private static Field[] fields(Type[] args) {
+        final Field[] result = new Field[args.length];
+
+        for (int i = 0; i < args.length; i++) {
+            final String name = new StringBuilder("f").append(i + 1).toString();
+            result[i] = new Field(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, name, args[i]);
+        }
+        return result;
+    }
+
+    @Override
+    public Type build() {
+        generateHelper();
+        begin();
+        init();
+        impl();
+        visitEnd();
+        owner.privilizer().env.debug("Generated %s implementation %s to call %s#%s", actionInterface.getClassName(),
+            action.getClassName(), owner.target.getClassName(), helper);
+        return action;
+    }
+
+    /**
+     * We must add special methods for inner classes to invoke their owners' methods, according to the scheme "access$n"
+     * where n is the index into this (ordered) map. Additionally we will prefix the whole thing like we usually do
+     * (__privileged_):
+     */
+    private void generateHelper() {
+        owner.privilizer().env.debug("Generating static helper method %s.%s to call %s", owner.target.getClassName(),
+            helper, impl);
+        final GeneratorAdapter mg =
+            new GeneratorAdapter(Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, helper, null, exceptions, owner);
+
+        mg.visitCode();
+        mg.loadArgs();
+        if (implIsStatic) {
+            mg.invokeStatic(owner.target, impl);
+        } else {
+            mg.invokeVirtual(owner.target, impl);
+        }
+        mg.returnValue();
+        mg.endMethod();
+    }
+
+    private void begin() {
+        owner.visitInnerClass(action.getInternalName(), owner.className, simpleName, Opcodes.ACC_PRIVATE
+            | Opcodes.ACC_STATIC);
+
+        final SignatureWriter type = new SignatureWriter();
+        final SignatureVisitor actionImplemented = type.visitInterface();
+        actionImplemented.visitClassType(actionInterface.getInternalName());
+        final SignatureVisitor visitTypeArgument = actionImplemented.visitTypeArgument('=');
+        final SignatureReader result = new SignatureReader(privilizer().wrap(m.getReturnType()).getDescriptor());
+        result.accept(visitTypeArgument);
+        actionImplemented.visitEnd();
+
+        final String signature = type.toString();
+
+        visit(Opcodes.V1_5, Opcodes.ACC_SUPER | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_FINAL, action.getInternalName(),
+            signature, Type.getType(Object.class).getInternalName(),
+            new String[] { actionInterface.getInternalName() });
+    }
+
+    /**
+     * Add fields and generate constructor.
+     */
+    private void init() {
+        for (Field field : fields) {
+            visitField(field.access, field.name, field.type.getDescriptor(), null, null).visitEnd();
+        }
+        final Method init = new Method("<init>", Type.VOID_TYPE, helper.getArgumentTypes());
+
+        final GeneratorAdapter mg =
+            new GeneratorAdapter(0, init, null, Privilizer.EMPTY_TYPE_ARRAY, this);
+
+        mg.visitCode();
+        final Label begin = mg.mark();
+
+        // invoke super constructor
+        mg.loadThis();
+        mg.invokeConstructor(Type.getType(Object.class), Method.getMethod("void <init> ()"));
+        // assign remaining fields
+
+        int arg = 0;
+        for (Field field : fields) {
+            mg.loadThis();
+            mg.loadArg(arg++);
+            mg.putField(action, field.name, field.type);
+        }
+
+        mg.returnValue();
+        final Label end = mg.mark();
+
+        // declare local vars
+        mg.visitLocalVariable("this", action.getDescriptor(), null, begin, end, 0);
+        arg = 1;
+        for (Field field : fields) {
+            mg.visitLocalVariable("arg" + arg, field.type.getDescriptor(), null, begin, end, arg++);
+        }
+        mg.endMethod();
+    }
+
+    /**
+     * Generate impl method.
+     */
+    private void impl() {
+        final Method run = Method.getMethod("Object run()");
+
+        final GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, run, null, exceptions, this);
+
+        for (Field field : fields) {
+            mg.loadThis();
+            mg.getField(action, field.name, field.type);
+        }
+
+        mg.invokeStatic(owner.target, helper);
+
+        if (m.getReturnType().getSort() < Type.ARRAY) {
+            mg.valueOf(m.getReturnType());
+        }
+
+        mg.returnValue();
+
+        mg.endMethod();
+    }
+
+}

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/ActionGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/ActionGenerator.java
            ('svn:executable' removed)

Modified: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java
URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java?rev=1567781&r1=1567780&r2=1567781&view=diff
==============================================================================
--- commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java (original)
+++ commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java Wed Feb 12 22:40:06 2014
@@ -1,490 +1,490 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.commons.weaver.privilizer;
-
-import java.io.InputStream;
-import java.lang.reflect.Modifier;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.Validate;
-import org.apache.commons.lang3.mutable.MutableObject;
-import org.apache.commons.lang3.tuple.Pair;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.FieldVisitor;
-import org.objectweb.asm.Label;
-import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.Type;
-import org.objectweb.asm.commons.AdviceAdapter;
-import org.objectweb.asm.commons.GeneratorAdapter;
-import org.objectweb.asm.commons.Method;
-import org.objectweb.asm.tree.ClassNode;
-import org.objectweb.asm.tree.MethodNode;
-
-/**
- * {@link ClassVisitor} to import so-called "blueprint methods".
- */
-class BlueprintingVisitor extends Privilizer.PrivilizerClassVisitor {
-
-    private final Set<Type> blueprintTypes = new HashSet<Type>();
-    private final Map<Pair<Type, Method>, MethodNode> blueprintRegistry = new HashMap<Pair<Type, Method>, MethodNode>();
-
-    private final Map<Pair<Type, Method>, String> importedMethods = new HashMap<Pair<Type, Method>, String>();
-
-    private final Map<Type, Map<Method, MethodNode>> methodCache = new HashMap<Type, Map<Method, MethodNode>>();
-    private final Map<Pair<Type, String>, FieldAccess> fieldAccessMap = new HashMap<Pair<Type, String>, FieldAccess>();
-
-    private final ClassVisitor next;
-
-    /**
-     * Create a new {@link BlueprintingVisitor}.
-     * @param privilizer owner
-     * @param cv wrapped
-     * @param config annotation
-     */
-    BlueprintingVisitor(Privilizer privilizer, ClassVisitor cv, Privilizing config) {
-        privilizer.super(new ClassNode(Opcodes.ASM4));
-        this.next = cv;
-
-        // load up blueprint methods:
-        for (Privilizing.CallTo callTo : config.value()) {
-            final Type blueprintType = Type.getType(callTo.value());
-            blueprintTypes.add(blueprintType);
-            for (Map.Entry<Method, MethodNode> e : getMethods(blueprintType).entrySet()) {
-                boolean found = false;
-                if (callTo.methods().length == 0) {
-                    found = true;
-                } else {
-                    for (String name : callTo.methods()) {
-                        if (e.getKey().getName().equals(name)) {
-                            found = true;
-                            break;
-                        }
-                    }
-                }
-                if (found) {
-                    blueprintRegistry.put(Pair.of(blueprintType, e.getKey()), e.getValue());
-                }
-            }
-        }
-    }
-
-    private Map<Method, MethodNode> getMethods(final Type type) {
-        if (methodCache.containsKey(type)) {
-            return methodCache.get(type);
-        }
-        final ClassNode classNode = read(type.getClassName());
-        final Map<Method, MethodNode> result = new HashMap<Method, MethodNode>();
-
-        @SuppressWarnings("unchecked")
-        final List<MethodNode> methods = classNode.methods;
-
-        for (MethodNode methodNode : methods) {
-            if (Modifier.isStatic(methodNode.access) && !"<clinit>".equals(methodNode.name)) {
-                result.put(new Method(methodNode.name, methodNode.desc), methodNode);
-            }
-        }
-        methodCache.put(type, result);
-        return result;
-    }
-
-    private ClassNode read(String className) {
-        final ClassNode result = new ClassNode(Opcodes.ASM4);
-        InputStream bytecode = null;
-        try {
-            bytecode = privilizer().env.getClassfile(className).getInputStream();
-            new ClassReader(bytecode).accept(result, ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        } finally {
-            IOUtils.closeQuietly(bytecode);
-        }
-        return result;
-    }
-
-    @Override
-    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
-        Validate.isTrue(!blueprintTypes.contains(Type.getObjectType(name)),
-            "Class %s cannot declare itself as a blueprint!", name);
-        super.visit(version, access, name, signature, superName, interfaces);
-    }
-
-    @Override
-    public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
-        final MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
-        return new MethodInvocationHandler(mv) {
-            @Override
-            boolean shouldImport(Pair<Type, Method> methodKey) {
-                return blueprintRegistry.containsKey(methodKey);
-            }
-        };
-    }
-
-    private String importMethod(Pair<Type, Method> key) {
-        if (importedMethods.containsKey(key)) {
-            return importedMethods.get(key);
-        }
-        final String result =
-            new StringBuilder(key.getLeft().getInternalName().replace('/', '_')).append("$$")
-                .append(key.getRight().getName()).toString();
-        importedMethods.put(key, result);
-        privilizer().env.debug("importing %s#%s as %s", key.getLeft().getClassName(), key.getRight(), result);
-        final int access = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC;
-
-        final MethodNode source = getMethods(key.getLeft()).get(key.getRight());
-
-        @SuppressWarnings("unchecked")
-        final String[] exceptions = (String[]) source.exceptions.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
-
-        // non-public fields accessed
-        final Set<FieldAccess> fieldAccesses = new LinkedHashSet<FieldAccess>();
-
-        source.accept(new MethodVisitor(Opcodes.ASM4) {
-            @Override
-            public void visitFieldInsn(int opcode, String owner, String name, String desc) {
-                final FieldAccess fieldAccess = fieldAccess(Type.getObjectType(owner), name, Type.getType(desc));
-
-                super.visitFieldInsn(opcode, owner, name, desc);
-                if (!Modifier.isPublic(fieldAccess.access)) {
-                    fieldAccesses.add(fieldAccess);
-                }
-            }
-        });
-
-        final MethodNode withAccessibleAdvice =
-            new MethodNode(access, result, source.desc, source.signature, exceptions);
-
-        // spider own methods:
-        MethodVisitor mv = new NestedMethodInvocationHandler(withAccessibleAdvice, key.getLeft());
-
-        if (!fieldAccesses.isEmpty()) {
-            // accessesNonPublicFields = true;
-            mv = new AccessibleAdvisor(mv, access, result, source.desc, new ArrayList<FieldAccess>(fieldAccesses));
-        }
-
-        source.accept(mv);
-
-        if (Modifier.isPrivate(source.access)) {
-            // can only be called by other privileged methods, so no need to mark as privileged
-        } else {
-            withAccessibleAdvice.visitAnnotation(Type.getType(Privileged.class).getDescriptor(), false).visitEnd();
-        }
-
-        withAccessibleAdvice.accept(this.cv);
-
-        return result;
-    }
-
-    private FieldAccess fieldAccess(final Type owner, String name, Type desc) {
-        final Pair<Type, String> key = Pair.of(owner, name);
-        if (!fieldAccessMap.containsKey(key)) {
-            try {
-                final MutableObject<Type> next = new MutableObject<Type>(owner);
-                final Deque<Type> stk = new ArrayDeque<Type>();
-                while (next.getValue() != null) {
-                    stk.push(next.getValue());
-                    InputStream bytecode = null;
-                    try {
-                        bytecode = privilizer().env.getClassfile(next.getValue().getInternalName()).getInputStream();
-                        new ClassReader(bytecode).accept(privilizer().new PrivilizerClassVisitor() {
-                            @Override
-                            public void visit(int version, int access, String name, String signature, String superName,
-                                String[] interfaces) {
-                                super.visit(version, access, name, signature, superName, interfaces);
-                                next.setValue(Type.getObjectType(superName));
-                            }
-
-                            @Override
-                            public FieldVisitor visitField(int access, String name, String desc, String signature,
-                                Object value) {
-                                for (Type type : stk) {
-                                    final Pair<Type, String> k = Pair.of(type, name);
-                                    // skip shadowed fields:
-                                    if (!fieldAccessMap.containsKey(k)) {
-                                        fieldAccessMap.put(k,
-                                            new FieldAccess(access, target, name, Type.getType(desc)));
-                                    }
-                                }
-                                return null;
-                            }
-                        }, ClassReader.SKIP_CODE);
-                    } finally {
-                        IOUtils.closeQuietly(bytecode);
-                    }
-                    if (fieldAccessMap.containsKey(key)) {
-                        break;
-                    }
-                }
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-            Validate.isTrue(fieldAccessMap.containsKey(key), "Could not locate %s.%s", owner.getClassName(), name);
-        }
-        return fieldAccessMap.get(key);
-    }
-
-    @Override
-    public void visitEnd() {
-        super.visitEnd();
-        ((ClassNode) cv).accept(next);
-    }
-
-    private abstract class MethodInvocationHandler extends MethodVisitor {
-        MethodInvocationHandler(MethodVisitor mv) {
-            super(Opcodes.ASM4, mv);
-        }
-
-        @Override
-        public void visitMethodInsn(int opcode, String owner, String name, String desc) {
-            if (opcode == Opcodes.INVOKESTATIC) {
-                final Method m = new Method(name, desc);
-                final Pair<Type, Method> methodKey = Pair.of(Type.getObjectType(owner), m);
-                if (shouldImport(methodKey)) {
-                    final String importedName = importMethod(methodKey);
-                    super.visitMethodInsn(opcode, className, importedName, desc);
-                    return;
-                }
-            }
-            super.visitMethodInsn(opcode, owner, name, desc);
-        }
-
-        abstract boolean shouldImport(Pair<Type, Method> methodKey);
-    }
-
-    class NestedMethodInvocationHandler extends MethodInvocationHandler {
-        final Type owner;
-
-        NestedMethodInvocationHandler(MethodVisitor mv, Type owner) {
-            super(mv);
-            this.owner = owner;
-        }
-
-        @Override
-        boolean shouldImport(Pair<Type, Method> methodKey) {
-            // call anything called within a class hierarchy:
-            final Type called = methodKey.getLeft();
-            // "I prefer the short cut":
-            if (called.equals(owner)) {
-                return true;
-            }
-            try {
-                final Class<?> inner = load(called);
-                final Class<?> outer = load(owner);
-                return inner.isAssignableFrom(outer);
-            } catch (ClassNotFoundException e) {
-                return false;
-            }
-        }
-
-        private Class<?> load(Type t) throws ClassNotFoundException {
-            return privilizer().env.classLoader.loadClass(t.getClassName());
-        }
-    }
-
-    /**
-     * For every non-public referenced field of an imported method, replaces with reflective calls. Additionally, for
-     * every such field that is not accessible, sets the field's accessibility and clears it as the method exits.
-     */
-    private class AccessibleAdvisor extends AdviceAdapter {
-        final Type bitSetType = Type.getType(BitSet.class);
-        final Type classType = Type.getType(Class.class);
-        final Type fieldType = Type.getType(java.lang.reflect.Field.class);
-        final Type fieldArrayType = Type.getType(java.lang.reflect.Field[].class);
-        final Type stringType = Type.getType(String.class);
-
-        final List<FieldAccess> fieldAccesses;
-        final Label begin = new Label();
-        int localFieldArray;
-        int bitSet;
-        int fieldCounter;
-
-        AccessibleAdvisor(MethodVisitor mv, int access, String name, String desc, List<FieldAccess> fieldAccesses) {
-            super(ASM4, mv, access, name, desc);
-            this.fieldAccesses = fieldAccesses;
-        }
-
-        @Override
-        protected void onMethodEnter() {
-            localFieldArray = newLocal(fieldArrayType);
-            bitSet = newLocal(bitSetType);
-            fieldCounter = newLocal(Type.INT_TYPE);
-
-            // create localFieldArray
-            push(fieldAccesses.size());
-            newArray(fieldArrayType.getElementType());
-            storeLocal(localFieldArray);
-
-            // create bitSet
-            newInstance(bitSetType);
-            dup();
-            push(fieldAccesses.size());
-            invokeConstructor(bitSetType, Method.getMethod("void <init>(int)"));
-            storeLocal(bitSet);
-
-            // populate localFieldArray
-            push(0);
-            storeLocal(fieldCounter);
-            for (FieldAccess access : fieldAccesses) {
-                prehandle(access);
-                iinc(fieldCounter, 1);
-            }
-            mark(begin);
-        }
-
-        private void prehandle(FieldAccess access) {
-            // push owner.class literal
-            visitLdcInsn(access.owner);
-            push(access.name);
-            final Label next = new Label();
-            invokeVirtual(classType, new Method("getDeclaredField", fieldType, new Type[] { stringType }));
-
-            dup();
-            // store the field at localFieldArray[fieldCounter]:
-            loadLocal(localFieldArray);
-            swap();
-            loadLocal(fieldCounter);
-            swap();
-            arrayStore(fieldArrayType.getElementType());
-
-            dup();
-            invokeVirtual(fieldArrayType.getElementType(), Method.getMethod("boolean isAccessible()"));
-
-            final Label setAccessible = new Label();
-            // if false, setAccessible:
-            ifZCmp(EQ, setAccessible);
-
-            // else pop field instance
-            pop();
-            // and record that he was already accessible:
-            loadLocal(bitSet);
-            loadLocal(fieldCounter);
-            invokeVirtual(bitSetType, Method.getMethod("void set(int)"));
-            goTo(next);
-
-            mark(setAccessible);
-            push(true);
-            invokeVirtual(fieldArrayType.getElementType(), Method.getMethod("void setAccessible(boolean)"));
-
-            mark(next);
-        }
-
-        @Override
-        public void visitFieldInsn(int opcode, String owner, String name, String desc) {
-            final Pair<Type, String> key = Pair.of(Type.getObjectType(owner), name);
-            final FieldAccess fieldAccess = fieldAccessMap.get(key);
-            Validate.isTrue(fieldAccesses.contains(fieldAccess), "Cannot find field %s", key);
-            final int fieldIndex = fieldAccesses.indexOf(fieldAccess);
-            visitInsn(NOP);
-            loadLocal(localFieldArray);
-            push(fieldIndex);
-            arrayLoad(fieldArrayType.getElementType());
-            checkCast(fieldType);
-
-            final Method access;
-            if (opcode == PUTSTATIC) {
-                // value should have been at top of stack on entry; position the field under the value:
-                swap();
-                // add null object for static field deref and swap under value:
-                push((String) null);
-                swap();
-                if (fieldAccess.type.getSort() < Type.ARRAY) {
-                    // box value:
-                    valueOf(fieldAccess.type);
-                }
-                access = Method.getMethod("void set(Object, Object)");
-            } else {
-                access = Method.getMethod("Object get(Object)");
-                // add null object for static field deref:
-                push((String) null);
-            }
-
-            invokeVirtual(fieldType, access);
-
-            if (opcode == GETSTATIC) {
-                checkCast(privilizer().wrap(fieldAccess.type));
-                if (fieldAccess.type.getSort() < Type.ARRAY) {
-                    unbox(fieldAccess.type);
-                }
-            }
-        }
-
-        @Override
-        public void visitMaxs(int maxStack, int maxLocals) {
-            // put try-finally around the whole method
-            final Label fy = mark();
-            // null exception type signifies finally block:
-            final Type exceptionType = null;
-            catchException(begin, fy, exceptionType);
-            onFinally();
-            throwException();
-            super.visitMaxs(maxStack, maxLocals);
-        }
-
-        @Override
-        protected void onMethodExit(int opcode) {
-            if (opcode != ATHROW) {
-                onFinally();
-            }
-        }
-
-        private void onFinally() {
-            // loop over fields and return any non-null element to being inaccessible:
-            push(0);
-            storeLocal(fieldCounter);
-
-            final Label test = mark();
-            final Label increment = new Label();
-            final Label endFinally = new Label();
-
-            loadLocal(fieldCounter);
-            push(fieldAccesses.size());
-            ifCmp(Type.INT_TYPE, GeneratorAdapter.GE, endFinally);
-
-            loadLocal(bitSet);
-            loadLocal(fieldCounter);
-            invokeVirtual(bitSetType, Method.getMethod("boolean get(int)"));
-
-            // if true, increment:
-            ifZCmp(NE, increment);
-
-            loadLocal(localFieldArray);
-            loadLocal(fieldCounter);
-            arrayLoad(fieldArrayType.getElementType());
-            push(false);
-            invokeVirtual(fieldArrayType.getElementType(), Method.getMethod("void setAccessible(boolean)"));
-
-            mark(increment);
-            iinc(fieldCounter, 1);
-            goTo(test);
-            mark(endFinally);
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.weaver.privilizer;
+
+import java.io.InputStream;
+import java.lang.reflect.Modifier;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+import org.apache.commons.lang3.mutable.MutableObject;
+import org.apache.commons.lang3.tuple.Pair;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.commons.AdviceAdapter;
+import org.objectweb.asm.commons.GeneratorAdapter;
+import org.objectweb.asm.commons.Method;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.MethodNode;
+
+/**
+ * {@link ClassVisitor} to import so-called "blueprint methods".
+ */
+class BlueprintingVisitor extends Privilizer.PrivilizerClassVisitor {
+
+    private final Set<Type> blueprintTypes = new HashSet<Type>();
+    private final Map<Pair<Type, Method>, MethodNode> blueprintRegistry = new HashMap<Pair<Type, Method>, MethodNode>();
+
+    private final Map<Pair<Type, Method>, String> importedMethods = new HashMap<Pair<Type, Method>, String>();
+
+    private final Map<Type, Map<Method, MethodNode>> methodCache = new HashMap<Type, Map<Method, MethodNode>>();
+    private final Map<Pair<Type, String>, FieldAccess> fieldAccessMap = new HashMap<Pair<Type, String>, FieldAccess>();
+
+    private final ClassVisitor next;
+
+    /**
+     * Create a new {@link BlueprintingVisitor}.
+     * @param privilizer owner
+     * @param cv wrapped
+     * @param config annotation
+     */
+    BlueprintingVisitor(Privilizer privilizer, ClassVisitor cv, Privilizing config) {
+        privilizer.super(new ClassNode(Opcodes.ASM4));
+        this.next = cv;
+
+        // load up blueprint methods:
+        for (Privilizing.CallTo callTo : config.value()) {
+            final Type blueprintType = Type.getType(callTo.value());
+            blueprintTypes.add(blueprintType);
+            for (Map.Entry<Method, MethodNode> e : getMethods(blueprintType).entrySet()) {
+                boolean found = false;
+                if (callTo.methods().length == 0) {
+                    found = true;
+                } else {
+                    for (String name : callTo.methods()) {
+                        if (e.getKey().getName().equals(name)) {
+                            found = true;
+                            break;
+                        }
+                    }
+                }
+                if (found) {
+                    blueprintRegistry.put(Pair.of(blueprintType, e.getKey()), e.getValue());
+                }
+            }
+        }
+    }
+
+    private Map<Method, MethodNode> getMethods(final Type type) {
+        if (methodCache.containsKey(type)) {
+            return methodCache.get(type);
+        }
+        final ClassNode classNode = read(type.getClassName());
+        final Map<Method, MethodNode> result = new HashMap<Method, MethodNode>();
+
+        @SuppressWarnings("unchecked")
+        final List<MethodNode> methods = classNode.methods;
+
+        for (MethodNode methodNode : methods) {
+            if (Modifier.isStatic(methodNode.access) && !"<clinit>".equals(methodNode.name)) {
+                result.put(new Method(methodNode.name, methodNode.desc), methodNode);
+            }
+        }
+        methodCache.put(type, result);
+        return result;
+    }
+
+    private ClassNode read(String className) {
+        final ClassNode result = new ClassNode(Opcodes.ASM4);
+        InputStream bytecode = null;
+        try {
+            bytecode = privilizer().env.getClassfile(className).getInputStream();
+            new ClassReader(bytecode).accept(result, ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            IOUtils.closeQuietly(bytecode);
+        }
+        return result;
+    }
+
+    @Override
+    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
+        Validate.isTrue(!blueprintTypes.contains(Type.getObjectType(name)),
+            "Class %s cannot declare itself as a blueprint!", name);
+        super.visit(version, access, name, signature, superName, interfaces);
+    }
+
+    @Override
+    public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
+        final MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
+        return new MethodInvocationHandler(mv) {
+            @Override
+            boolean shouldImport(Pair<Type, Method> methodKey) {
+                return blueprintRegistry.containsKey(methodKey);
+            }
+        };
+    }
+
+    private String importMethod(Pair<Type, Method> key) {
+        if (importedMethods.containsKey(key)) {
+            return importedMethods.get(key);
+        }
+        final String result =
+            new StringBuilder(key.getLeft().getInternalName().replace('/', '_')).append("$$")
+                .append(key.getRight().getName()).toString();
+        importedMethods.put(key, result);
+        privilizer().env.debug("importing %s#%s as %s", key.getLeft().getClassName(), key.getRight(), result);
+        final int access = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC;
+
+        final MethodNode source = getMethods(key.getLeft()).get(key.getRight());
+
+        @SuppressWarnings("unchecked")
+        final String[] exceptions = (String[]) source.exceptions.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
+
+        // non-public fields accessed
+        final Set<FieldAccess> fieldAccesses = new LinkedHashSet<FieldAccess>();
+
+        source.accept(new MethodVisitor(Opcodes.ASM4) {
+            @Override
+            public void visitFieldInsn(int opcode, String owner, String name, String desc) {
+                final FieldAccess fieldAccess = fieldAccess(Type.getObjectType(owner), name, Type.getType(desc));
+
+                super.visitFieldInsn(opcode, owner, name, desc);
+                if (!Modifier.isPublic(fieldAccess.access)) {
+                    fieldAccesses.add(fieldAccess);
+                }
+            }
+        });
+
+        final MethodNode withAccessibleAdvice =
+            new MethodNode(access, result, source.desc, source.signature, exceptions);
+
+        // spider own methods:
+        MethodVisitor mv = new NestedMethodInvocationHandler(withAccessibleAdvice, key.getLeft());
+
+        if (!fieldAccesses.isEmpty()) {
+            // accessesNonPublicFields = true;
+            mv = new AccessibleAdvisor(mv, access, result, source.desc, new ArrayList<FieldAccess>(fieldAccesses));
+        }
+
+        source.accept(mv);
+
+        if (Modifier.isPrivate(source.access)) {
+            // can only be called by other privileged methods, so no need to mark as privileged
+        } else {
+            withAccessibleAdvice.visitAnnotation(Type.getType(Privileged.class).getDescriptor(), false).visitEnd();
+        }
+
+        withAccessibleAdvice.accept(this.cv);
+
+        return result;
+    }
+
+    private FieldAccess fieldAccess(final Type owner, String name, Type desc) {
+        final Pair<Type, String> key = Pair.of(owner, name);
+        if (!fieldAccessMap.containsKey(key)) {
+            try {
+                final MutableObject<Type> next = new MutableObject<Type>(owner);
+                final Deque<Type> stk = new ArrayDeque<Type>();
+                while (next.getValue() != null) {
+                    stk.push(next.getValue());
+                    InputStream bytecode = null;
+                    try {
+                        bytecode = privilizer().env.getClassfile(next.getValue().getInternalName()).getInputStream();
+                        new ClassReader(bytecode).accept(privilizer().new PrivilizerClassVisitor() {
+                            @Override
+                            public void visit(int version, int access, String name, String signature, String superName,
+                                String[] interfaces) {
+                                super.visit(version, access, name, signature, superName, interfaces);
+                                next.setValue(Type.getObjectType(superName));
+                            }
+
+                            @Override
+                            public FieldVisitor visitField(int access, String name, String desc, String signature,
+                                Object value) {
+                                for (Type type : stk) {
+                                    final Pair<Type, String> k = Pair.of(type, name);
+                                    // skip shadowed fields:
+                                    if (!fieldAccessMap.containsKey(k)) {
+                                        fieldAccessMap.put(k,
+                                            new FieldAccess(access, target, name, Type.getType(desc)));
+                                    }
+                                }
+                                return null;
+                            }
+                        }, ClassReader.SKIP_CODE);
+                    } finally {
+                        IOUtils.closeQuietly(bytecode);
+                    }
+                    if (fieldAccessMap.containsKey(key)) {
+                        break;
+                    }
+                }
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            Validate.isTrue(fieldAccessMap.containsKey(key), "Could not locate %s.%s", owner.getClassName(), name);
+        }
+        return fieldAccessMap.get(key);
+    }
+
+    @Override
+    public void visitEnd() {
+        super.visitEnd();
+        ((ClassNode) cv).accept(next);
+    }
+
+    private abstract class MethodInvocationHandler extends MethodVisitor {
+        MethodInvocationHandler(MethodVisitor mv) {
+            super(Opcodes.ASM4, mv);
+        }
+
+        @Override
+        public void visitMethodInsn(int opcode, String owner, String name, String desc) {
+            if (opcode == Opcodes.INVOKESTATIC) {
+                final Method m = new Method(name, desc);
+                final Pair<Type, Method> methodKey = Pair.of(Type.getObjectType(owner), m);
+                if (shouldImport(methodKey)) {
+                    final String importedName = importMethod(methodKey);
+                    super.visitMethodInsn(opcode, className, importedName, desc);
+                    return;
+                }
+            }
+            super.visitMethodInsn(opcode, owner, name, desc);
+        }
+
+        abstract boolean shouldImport(Pair<Type, Method> methodKey);
+    }
+
+    class NestedMethodInvocationHandler extends MethodInvocationHandler {
+        final Type owner;
+
+        NestedMethodInvocationHandler(MethodVisitor mv, Type owner) {
+            super(mv);
+            this.owner = owner;
+        }
+
+        @Override
+        boolean shouldImport(Pair<Type, Method> methodKey) {
+            // call anything called within a class hierarchy:
+            final Type called = methodKey.getLeft();
+            // "I prefer the short cut":
+            if (called.equals(owner)) {
+                return true;
+            }
+            try {
+                final Class<?> inner = load(called);
+                final Class<?> outer = load(owner);
+                return inner.isAssignableFrom(outer);
+            } catch (ClassNotFoundException e) {
+                return false;
+            }
+        }
+
+        private Class<?> load(Type t) throws ClassNotFoundException {
+            return privilizer().env.classLoader.loadClass(t.getClassName());
+        }
+    }
+
+    /**
+     * For every non-public referenced field of an imported method, replaces with reflective calls. Additionally, for
+     * every such field that is not accessible, sets the field's accessibility and clears it as the method exits.
+     */
+    private class AccessibleAdvisor extends AdviceAdapter {
+        final Type bitSetType = Type.getType(BitSet.class);
+        final Type classType = Type.getType(Class.class);
+        final Type fieldType = Type.getType(java.lang.reflect.Field.class);
+        final Type fieldArrayType = Type.getType(java.lang.reflect.Field[].class);
+        final Type stringType = Type.getType(String.class);
+
+        final List<FieldAccess> fieldAccesses;
+        final Label begin = new Label();
+        int localFieldArray;
+        int bitSet;
+        int fieldCounter;
+
+        AccessibleAdvisor(MethodVisitor mv, int access, String name, String desc, List<FieldAccess> fieldAccesses) {
+            super(ASM4, mv, access, name, desc);
+            this.fieldAccesses = fieldAccesses;
+        }
+
+        @Override
+        protected void onMethodEnter() {
+            localFieldArray = newLocal(fieldArrayType);
+            bitSet = newLocal(bitSetType);
+            fieldCounter = newLocal(Type.INT_TYPE);
+
+            // create localFieldArray
+            push(fieldAccesses.size());
+            newArray(fieldArrayType.getElementType());
+            storeLocal(localFieldArray);
+
+            // create bitSet
+            newInstance(bitSetType);
+            dup();
+            push(fieldAccesses.size());
+            invokeConstructor(bitSetType, Method.getMethod("void <init>(int)"));
+            storeLocal(bitSet);
+
+            // populate localFieldArray
+            push(0);
+            storeLocal(fieldCounter);
+            for (FieldAccess access : fieldAccesses) {
+                prehandle(access);
+                iinc(fieldCounter, 1);
+            }
+            mark(begin);
+        }
+
+        private void prehandle(FieldAccess access) {
+            // push owner.class literal
+            visitLdcInsn(access.owner);
+            push(access.name);
+            final Label next = new Label();
+            invokeVirtual(classType, new Method("getDeclaredField", fieldType, new Type[] { stringType }));
+
+            dup();
+            // store the field at localFieldArray[fieldCounter]:
+            loadLocal(localFieldArray);
+            swap();
+            loadLocal(fieldCounter);
+            swap();
+            arrayStore(fieldArrayType.getElementType());
+
+            dup();
+            invokeVirtual(fieldArrayType.getElementType(), Method.getMethod("boolean isAccessible()"));
+
+            final Label setAccessible = new Label();
+            // if false, setAccessible:
+            ifZCmp(EQ, setAccessible);
+
+            // else pop field instance
+            pop();
+            // and record that he was already accessible:
+            loadLocal(bitSet);
+            loadLocal(fieldCounter);
+            invokeVirtual(bitSetType, Method.getMethod("void set(int)"));
+            goTo(next);
+
+            mark(setAccessible);
+            push(true);
+            invokeVirtual(fieldArrayType.getElementType(), Method.getMethod("void setAccessible(boolean)"));
+
+            mark(next);
+        }
+
+        @Override
+        public void visitFieldInsn(int opcode, String owner, String name, String desc) {
+            final Pair<Type, String> key = Pair.of(Type.getObjectType(owner), name);
+            final FieldAccess fieldAccess = fieldAccessMap.get(key);
+            Validate.isTrue(fieldAccesses.contains(fieldAccess), "Cannot find field %s", key);
+            final int fieldIndex = fieldAccesses.indexOf(fieldAccess);
+            visitInsn(NOP);
+            loadLocal(localFieldArray);
+            push(fieldIndex);
+            arrayLoad(fieldArrayType.getElementType());
+            checkCast(fieldType);
+
+            final Method access;
+            if (opcode == PUTSTATIC) {
+                // value should have been at top of stack on entry; position the field under the value:
+                swap();
+                // add null object for static field deref and swap under value:
+                push((String) null);
+                swap();
+                if (fieldAccess.type.getSort() < Type.ARRAY) {
+                    // box value:
+                    valueOf(fieldAccess.type);
+                }
+                access = Method.getMethod("void set(Object, Object)");
+            } else {
+                access = Method.getMethod("Object get(Object)");
+                // add null object for static field deref:
+                push((String) null);
+            }
+
+            invokeVirtual(fieldType, access);
+
+            if (opcode == GETSTATIC) {
+                checkCast(privilizer().wrap(fieldAccess.type));
+                if (fieldAccess.type.getSort() < Type.ARRAY) {
+                    unbox(fieldAccess.type);
+                }
+            }
+        }
+
+        @Override
+        public void visitMaxs(int maxStack, int maxLocals) {
+            // put try-finally around the whole method
+            final Label fy = mark();
+            // null exception type signifies finally block:
+            final Type exceptionType = null;
+            catchException(begin, fy, exceptionType);
+            onFinally();
+            throwException();
+            super.visitMaxs(maxStack, maxLocals);
+        }
+
+        @Override
+        protected void onMethodExit(int opcode) {
+            if (opcode != ATHROW) {
+                onFinally();
+            }
+        }
+
+        private void onFinally() {
+            // loop over fields and return any non-null element to being inaccessible:
+            push(0);
+            storeLocal(fieldCounter);
+
+            final Label test = mark();
+            final Label increment = new Label();
+            final Label endFinally = new Label();
+
+            loadLocal(fieldCounter);
+            push(fieldAccesses.size());
+            ifCmp(Type.INT_TYPE, GeneratorAdapter.GE, endFinally);
+
+            loadLocal(bitSet);
+            loadLocal(fieldCounter);
+            invokeVirtual(bitSetType, Method.getMethod("boolean get(int)"));
+
+            // if true, increment:
+            ifZCmp(NE, increment);
+
+            loadLocal(localFieldArray);
+            loadLocal(fieldCounter);
+            arrayLoad(fieldArrayType.getElementType());
+            push(false);
+            invokeVirtual(fieldArrayType.getElementType(), Method.getMethod("void setAccessible(boolean)"));
+
+            mark(increment);
+            iinc(fieldCounter, 1);
+            goTo(test);
+            mark(endFinally);
+        }
+    }
+}

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/BlueprintingVisitor.java
            ('svn:executable' removed)

Modified: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Field.java
URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Field.java?rev=1567781&r1=1567780&r2=1567781&view=diff
==============================================================================
--- commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Field.java (original)
+++ commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Field.java Wed Feb 12 22:40:06 2014
@@ -1,87 +1,87 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.commons.weaver.privilizer;
-
-import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.Validate;
-import org.objectweb.asm.Type;
-
-/**
- * Represents a Java field.
- */
-public class Field {
-    /**
-     * Access modifier.
-     */
-    public final int access;
-
-    /**
-     * Field name.
-     */
-    public final String name;
-
-    /**
-     * Field type.
-     */
-    public final Type type;
-
-    /**
-     * Create a new {@link Field}.
-     * @param access modifier
-     * @param name of field
-     * @param type of field
-     */
-    public Field(int access, String name, Type type) {
-        super();
-        this.access = access;
-        this.name = Validate.notNull(name);
-        this.type = Validate.notNull(type);
-    }
-
-    /**
-     * Considers name and type.
-     * @param obj to check for equality
-     * @return whether equal
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == this) {
-            return true;
-        }
-        if (!(obj instanceof Field)) {
-            return false;
-        }
-        final Field other = (Field) obj;
-        return StringUtils.equals(other.name, name) && ObjectUtils.equals(other.type, type);
-    }
-
-    /**
-     * Considers name and type.
-     * @return hashCode
-     */
-    @Override
-    public int hashCode() {
-        int result = 57 << 2;
-        result |= name.hashCode();
-        result <<= 4;
-        result |= type.hashCode();
-        return result;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.weaver.privilizer;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.Validate;
+import org.objectweb.asm.Type;
+
+/**
+ * Represents a Java field.
+ */
+public class Field {
+    /**
+     * Access modifier.
+     */
+    public final int access;
+
+    /**
+     * Field name.
+     */
+    public final String name;
+
+    /**
+     * Field type.
+     */
+    public final Type type;
+
+    /**
+     * Create a new {@link Field}.
+     * @param access modifier
+     * @param name of field
+     * @param type of field
+     */
+    public Field(int access, String name, Type type) {
+        super();
+        this.access = access;
+        this.name = Validate.notNull(name);
+        this.type = Validate.notNull(type);
+    }
+
+    /**
+     * Considers name and type.
+     * @param obj to check for equality
+     * @return whether equal
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof Field)) {
+            return false;
+        }
+        final Field other = (Field) obj;
+        return StringUtils.equals(other.name, name) && ObjectUtils.equals(other.type, type);
+    }
+
+    /**
+     * Considers name and type.
+     * @return hashCode
+     */
+    @Override
+    public int hashCode() {
+        int result = 57 << 2;
+        result |= name.hashCode();
+        result <<= 4;
+        result |= type.hashCode();
+        return result;
+    }
+}

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Field.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Field.java
            ('svn:executable' removed)

Modified: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FieldAccess.java
URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FieldAccess.java?rev=1567781&r1=1567780&r2=1567781&view=diff
==============================================================================
--- commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FieldAccess.java (original)
+++ commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FieldAccess.java Wed Feb 12 22:40:06 2014
@@ -1,71 +1,71 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.commons.weaver.privilizer;
-
-import org.objectweb.asm.Type;
-
-/**
- * Models the action of accessing a field by extending {@link Field} with an
- * accessing type.
- */
-public class FieldAccess extends Field {
-    /**
-     * {@link Type} from which field is accessed.
-     */
-    public final Type owner;
-
-    /**
-     * Create a new {@link FieldAccess}.
-     * @param access operation
-     * @param owner {@link Type} from which field is accessed.
-     * @param name of field
-     * @param type of field
-     */
-    public FieldAccess(int access, Type owner, String name, Type type) {
-        super(access, name, type);
-        this.owner = owner;
-    }
-
-    /**
-     * Compare against {@code obj} for equality.
-     * @param obj to compare
-     * @return whether Objects are equal
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == this) {
-            return true;
-        }
-        if (!(obj instanceof FieldAccess)) {
-            return false;
-        }
-        return super.equals(obj) && ((FieldAccess) obj).owner.equals(owner);
-    }
-
-    /**
-     * Generate a hashCode.
-     * @return int
-     */
-    @Override
-    public int hashCode() {
-        final int result = super.hashCode() << 4;
-        return result | owner.hashCode();
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.weaver.privilizer;
+
+import org.objectweb.asm.Type;
+
+/**
+ * Models the action of accessing a field by extending {@link Field} with an
+ * accessing type.
+ */
+public class FieldAccess extends Field {
+    /**
+     * {@link Type} from which field is accessed.
+     */
+    public final Type owner;
+
+    /**
+     * Create a new {@link FieldAccess}.
+     * @param access operation
+     * @param owner {@link Type} from which field is accessed.
+     * @param name of field
+     * @param type of field
+     */
+    public FieldAccess(int access, Type owner, String name, Type type) {
+        super(access, name, type);
+        this.owner = owner;
+    }
+
+    /**
+     * Compare against {@code obj} for equality.
+     * @param obj to compare
+     * @return whether Objects are equal
+     */
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        }
+        if (!(obj instanceof FieldAccess)) {
+            return false;
+        }
+        return super.equals(obj) && ((FieldAccess) obj).owner.equals(owner);
+    }
+
+    /**
+     * Generate a hashCode.
+     * @return int
+     */
+    @Override
+    public int hashCode() {
+        final int result = super.hashCode() << 4;
+        return result | owner.hashCode();
+    }
+
+}

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FieldAccess.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/FieldAccess.java
            ('svn:executable' removed)

Modified: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/InlineNestedPrivilegedCalls.java
URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/InlineNestedPrivilegedCalls.java?rev=1567781&r1=1567780&r2=1567781&view=diff
==============================================================================
--- commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/InlineNestedPrivilegedCalls.java (original)
+++ commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/InlineNestedPrivilegedCalls.java Wed Feb 12 22:40:06 2014
@@ -1,88 +1,88 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.commons.weaver.privilizer;
-
-import java.util.Map;
-
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.Opcodes;
-import org.objectweb.asm.commons.Method;
-import org.objectweb.asm.tree.ClassNode;
-
-/**
- * For any privileged method called from another privileged method (actually the internal implementation method copied
- * from the original method body) the call is replaced by a call to the target's internal implementation method, thus
- * avoiding nested privileged invocations when possible. Persists everything to a tree model until the parent is
- * complete; allowing us to use a tree model while yet building the high-level view as a stack of visitors.
- */
-class InlineNestedPrivilegedCalls extends ClassNode {
-    private final Privilizer privilizer;
-
-    private final ClassVisitor next;
-
-    /**
-     * Map of original method to name of internal implementation method.
-     */
-    private final Map<Method, String> privilegedMethods;
-
-    /**
-     * Create a new {@link InlineNestedPrivilegedCalls} object.
-     * @param privilizer owner
-     * @param privilegedMethods map of original method to name of internal implementation method
-     * @param next visitor
-     */
-    InlineNestedPrivilegedCalls(Privilizer privilizer, Map<Method, String> privilegedMethods, ClassVisitor next) {
-        super(Opcodes.ASM4);
-        this.privilizer = privilizer;
-        this.privilegedMethods = privilegedMethods;
-        this.next = next;
-    }
-
-    @Override
-    public void visitEnd() {
-        super.visitEnd();
-
-        accept(new ClassVisitor(Opcodes.ASM4, next) {
-            @Override
-            public MethodVisitor visitMethod(int access, final String name, String desc, String signature,
-                String[] exceptions) {
-                final Method outer = new Method(name, desc);
-                final MethodVisitor orig = super.visitMethod(access, name, desc, signature, exceptions);
-                if (privilegedMethods.containsValue(name)) {
-                    return new MethodVisitor(Opcodes.ASM4, orig) {
-                        public void visitMethodInsn(int opcode, String owner, String name, String desc) {
-                            String useName = name;
-                            if (owner.equals(InlineNestedPrivilegedCalls.this.name)) {
-                                final Method m = new Method(name, desc);
-                                if (privilegedMethods.containsKey(m)) {
-                                    useName = privilegedMethods.get(m);
-                                    privilizer.env.debug("Inlining call from %s to %s as %s", outer, m,
-                                        useName);
-                                }
-                            }
-                            super.visitMethodInsn(opcode, owner, useName, desc);
-                        }
-                    };
-                }
-                return orig;
-            }
-        });
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.weaver.privilizer;
+
+import java.util.Map;
+
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.commons.Method;
+import org.objectweb.asm.tree.ClassNode;
+
+/**
+ * For any privileged method called from another privileged method (actually the internal implementation method copied
+ * from the original method body) the call is replaced by a call to the target's internal implementation method, thus
+ * avoiding nested privileged invocations when possible. Persists everything to a tree model until the parent is
+ * complete; allowing us to use a tree model while yet building the high-level view as a stack of visitors.
+ */
+class InlineNestedPrivilegedCalls extends ClassNode {
+    private final Privilizer privilizer;
+
+    private final ClassVisitor next;
+
+    /**
+     * Map of original method to name of internal implementation method.
+     */
+    private final Map<Method, String> privilegedMethods;
+
+    /**
+     * Create a new {@link InlineNestedPrivilegedCalls} object.
+     * @param privilizer owner
+     * @param privilegedMethods map of original method to name of internal implementation method
+     * @param next visitor
+     */
+    InlineNestedPrivilegedCalls(Privilizer privilizer, Map<Method, String> privilegedMethods, ClassVisitor next) {
+        super(Opcodes.ASM4);
+        this.privilizer = privilizer;
+        this.privilegedMethods = privilegedMethods;
+        this.next = next;
+    }
+
+    @Override
+    public void visitEnd() {
+        super.visitEnd();
+
+        accept(new ClassVisitor(Opcodes.ASM4, next) {
+            @Override
+            public MethodVisitor visitMethod(int access, final String name, String desc, String signature,
+                String[] exceptions) {
+                final Method outer = new Method(name, desc);
+                final MethodVisitor orig = super.visitMethod(access, name, desc, signature, exceptions);
+                if (privilegedMethods.containsValue(name)) {
+                    return new MethodVisitor(Opcodes.ASM4, orig) {
+                        public void visitMethodInsn(int opcode, String owner, String name, String desc) {
+                            String useName = name;
+                            if (owner.equals(InlineNestedPrivilegedCalls.this.name)) {
+                                final Method m = new Method(name, desc);
+                                if (privilegedMethods.containsKey(m)) {
+                                    useName = privilegedMethods.get(m);
+                                    privilizer.env.debug("Inlining call from %s to %s as %s", outer, m,
+                                        useName);
+                                }
+                            }
+                            super.visitMethodInsn(opcode, owner, useName, desc);
+                        }
+                    };
+                }
+                return orig;
+            }
+        });
+    }
+}

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/InlineNestedPrivilegedCalls.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/InlineNestedPrivilegedCalls.java
            ('svn:executable' removed)

Modified: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Policy.java
URL: http://svn.apache.org/viewvc/commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Policy.java?rev=1567781&r1=1567780&r2=1567781&view=diff
==============================================================================
--- commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Policy.java (original)
+++ commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Policy.java Wed Feb 12 22:40:06 2014
@@ -1,79 +1,79 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.commons.weaver.privilizer;
-
-import java.security.PrivilegedAction;
-import java.util.Locale;
-
-import org.apache.commons.lang3.StringUtils;
-
-/**
- * Weaving policy: when to use {@link PrivilegedAction}s.
- */
-public enum Policy {
-    /**
-     * Disables weaving.
-     */
-    NEVER,
-
-    /**
-     * Weaves such that the check for an active {@link SecurityManager} is done once only.
-     */
-    ON_INIT,
-
-    /**
-     * Weaves such that the check for an active {@link SecurityManager} is done for each {@link Privileged} method
-     * execution.
-     */
-    DYNAMIC,
-
-    /**
-     * Weaves such that {@link Privileged} methods are always executed as such.
-     */
-    ALWAYS;
-
-    /**
-     * Get the {@link Policy} value that should be used as a default.
-     * @return {@link Policy#DYNAMIC}
-     */
-    public static Policy defaultValue() {
-        return DYNAMIC;
-    }
-
-    /**
-     * Parse from a {@link String} returning {@link #defaultValue()} for blank/null input.
-     * @param s to parse
-     * @return {@link Policy}
-     */
-    public static Policy parse(String s) {
-        if (StringUtils.isBlank(s)) {
-            return defaultValue();
-        }
-        return valueOf(s.trim().toUpperCase(Locale.US));
-    }
-
-    /**
-     * Learn whether this is a conditional {@link Policy}.
-     * @return {@code this == ON_INIT || this == DYNAMIC}
-     */
-    public boolean isConditional() {
-        return this == ON_INIT || this == DYNAMIC;
-    }
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.weaver.privilizer;
+
+import java.security.PrivilegedAction;
+import java.util.Locale;
+
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * Weaving policy: when to use {@link PrivilegedAction}s.
+ */
+public enum Policy {
+    /**
+     * Disables weaving.
+     */
+    NEVER,
+
+    /**
+     * Weaves such that the check for an active {@link SecurityManager} is done once only.
+     */
+    ON_INIT,
+
+    /**
+     * Weaves such that the check for an active {@link SecurityManager} is done for each {@link Privileged} method
+     * execution.
+     */
+    DYNAMIC,
+
+    /**
+     * Weaves such that {@link Privileged} methods are always executed as such.
+     */
+    ALWAYS;
+
+    /**
+     * Get the {@link Policy} value that should be used as a default.
+     * @return {@link Policy#DYNAMIC}
+     */
+    public static Policy defaultValue() {
+        return DYNAMIC;
+    }
+
+    /**
+     * Parse from a {@link String} returning {@link #defaultValue()} for blank/null input.
+     * @param s to parse
+     * @return {@link Policy}
+     */
+    public static Policy parse(String s) {
+        if (StringUtils.isBlank(s)) {
+            return defaultValue();
+        }
+        return valueOf(s.trim().toUpperCase(Locale.US));
+    }
+
+    /**
+     * Learn whether this is a conditional {@link Policy}.
+     * @return {@code this == ON_INIT || this == DYNAMIC}
+     */
+    public boolean isConditional() {
+        return this == ON_INIT || this == DYNAMIC;
+    }
+
 }
\ No newline at end of file

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Policy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/weaver/trunk/modules/privilizer/weaver/src/main/java/org/apache/commons/weaver/privilizer/Policy.java
            ('svn:executable' removed)



Mime
View raw message