ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/PrivilegedFutureTask.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/PrivilegedFutureTask.java (file contents):
Revision 1.1 by tim, Sat Oct 25 04:23:25 2003 UTC vs.
Revision 1.2 by tim, Tue Oct 28 13:25:02 2003 UTC

# Line 31 | Line 31 | public class PrivilegedFutureTask<T> ext
31       *         does not have permission to both set and get context class loader.
32       */
33      public PrivilegedFutureTask(Callable<T> task) {
34        this(task,
35             Thread.currentThread().getContextClassLoader(),
36             AccessController.getContext());
37    }
38    
39    /**
40     * Constructs a <tt>PrivilegedFutureTask</tt> that will, upon running,
41     * execute the given <tt>Callable</tt> under the current access control
42     * context, with the given class loader as the context class loader,
43     *
44     * @throws AccessControlException if <tt>ccl</tt> is non-null and
45     *         the current access control context does not have permission
46     *         to both set and get context class loader.
47     */
48    public PrivilegedFutureTask(Callable<T> task, ClassLoader ccl) {
49        this(task, ccl, AccessController.getContext());
50    }
51    
52    /**
53     * Constructs a <tt>PrivilegedFutureTask</tt> that will, upon running,
54     * execute the given <tt>Callable</tt> with the current context class
55     * loader as the context class loader and the given access control
56     * context as the current access control context.
57     *
58     * @throws AccessControlException if <tt>acc</tt>is non-null and
59     *         <tt>acc</tt> does not have permission to both set and get
60     *         context class loader.
61     */
62    public PrivilegedFutureTask(Callable<T> task, AccessControlContext acc) {
63        this(task, Thread.currentThread().getContextClassLoader(), acc);
64    }
65    
66    /**
67     * Constructs a <tt>PrivilegedFutureTask</tt> that will, upon running,
68     * execute the given <tt>Callable</tt> with the given class loader as
69     * the context class loader and the given access control context as the
70     * current access control context.
71     *
72     * @throws AccessControlException if both <tt>ccl</tt> and <tt>acc</tt>
73     *         arguments are non-null and <tt>acc</tt> does not have permission
74     *         to both set and get context class loader.
75     */
76    public PrivilegedFutureTask(Callable<T> task, ClassLoader ccl, AccessControlContext acc) {
34          super(task);
35 <        if (ccl != null && acc != null) {
36 <            acc.checkPermission(new RuntimePermission("getContextClassLoader"));
37 <            acc.checkPermission(new RuntimePermission("setContextClassLoader"));
38 <        }
39 <        this.ccl = ccl;
83 <        this.acc = acc;
35 >        this.ccl = Thread.currentThread().getContextClassLoader();
36 >        this.acc = AccessController.getContext();
37 >        
38 >        acc.checkPermission(new RuntimePermission("getContextClassLoader"));
39 >        acc.checkPermission(new RuntimePermission("setContextClassLoader"));
40      }
41  
42  
43      public void run() {
44 <        if (acc != null)
45 <            AccessController.doPrivileged(new PrivilegedAction() {
46 <                public Object run() {
47 <                    runPrivileged();
48 <                    return null;
49 <                }
94 <            }, acc);
95 <        else
96 <            runUnprivileged();
44 >        AccessController.doPrivileged(new PrivilegedAction() {
45 >            public Object run() {
46 >                runPrivileged();
47 >                return null;
48 >            }
49 >        }, acc);
50      }
51  
52  
53      private void runPrivileged() {
54          ClassLoader saved = null;
55 <        if (ccl != null) {
55 >        try {
56              ClassLoader current = Thread.currentThread().getContextClassLoader();
57              if (ccl != current) {
58                  Thread.currentThread().setContextClassLoader(ccl);
59                  saved = current;
60              }
108        }
109
110        try {
111            super.run();
112        }
113        finally {
114            if (saved != null)
115                Thread.currentThread().setContextClassLoader(saved);
116        }
117    }
118
119    private void runUnprivileged() {
120        ClassLoader saved = null;
121        if (ccl != null) {
122            ClassLoader current = null;
123            try {
124                current = Thread.currentThread().getContextClassLoader();
125            }
126            catch (AccessControlException e) {}
127
128            if (current != null && ccl != current) {
129                try {
130                    Thread.currentThread().setContextClassLoader(ccl);
131                    // we only get here if we successfully set a CCL
132                    // different from the current CCL
133                    saved = current;
134                }
135                catch (AccessControlException e) {}
136            }
137        }
138        try {
61              super.run();
62          }
63          finally {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines