src/share/jaxws_classes/com/sun/tools/internal/xjc/Driver.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -29,10 +29,12 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Iterator;
 
 import com.sun.codemodel.internal.CodeWriter;
 import com.sun.codemodel.internal.JCodeModel;
 import com.sun.codemodel.internal.writer.ZipCodeWriter;

@@ -62,18 +64,16 @@
 /**
  * Command Line Interface of XJC.
  */
 public class Driver {
 
+    private static final String SYSTEM_PROXY_PROPERTY = "java.net.useSystemProxies";
+
     public static void main(final String[] args) throws Exception {
         // use the platform default proxy if available.
         // see sun.net.spi.DefaultProxySelector for details.
-        try {
-            System.setProperty("java.net.useSystemProxies","true");
-        } catch (SecurityException e) {
-            // failing to set this property isn't fatal
-        }
+        setupProxies();
 
         if( Util.getSystemProperty(Driver.class,"noThreadSwap")!=null )
             _main(args);    // for the ease of debugging
 
         // run all the work in another thread so that the -Xss option

@@ -101,10 +101,31 @@
             else
                 throw (Error)ex[0];
         }
     }
 
+    /**
+     * Set useSystemProxies if needed
+     */
+    private static void setupProxies() {
+        Object setProperty = AccessController.doPrivileged(new PrivilegedAction<Object>() {
+            @Override
+            public Object run() {
+                return System.getProperty(SYSTEM_PROXY_PROPERTY);
+            }
+        });
+        if (setProperty == null) {
+            AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                @Override
+                public Void run() {
+                    System.setProperty(SYSTEM_PROXY_PROPERTY, "true");
+                    return null;
+                }
+            });
+        }
+    }
+
     private static void _main( String[] args ) throws Exception {
         try {
             System.exit(run( args, System.out, System.out ));
         } catch (BadCommandLineException e) {
             // there was an error in the command line.