< prev index next >

src/share/classes/java/net/URL.java

Print this page
rev 1564 : 7090158: Networking Libraries don't build with javac -Werror
7125055: ContentHandler.getContent API changed in error
Summary: Minor changes to networking java files to remove warnings
Reviewed-by: chegar, weijun, hawtin, alanb
Contributed-by: kurchi.subhra.hazra@oracle.com, sasha_bu@hotmail.com


1099      * @see        java.net.URLStreamHandlerFactory
1100      * @see        SecurityManager#checkSetFactory
1101      */
1102     public static void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) {
1103         synchronized (streamHandlerLock) {
1104             if (factory != null) {
1105                 throw new Error("factory already defined");
1106             }
1107             SecurityManager security = System.getSecurityManager();
1108             if (security != null) {
1109                 security.checkSetFactory();
1110             }
1111             handlers.clear();
1112             factory = fac;
1113         }
1114     }
1115 
1116     /**
1117      * A table of protocol handlers.
1118      */
1119     static Hashtable handlers = new Hashtable();
1120     private static Object streamHandlerLock = new Object();
1121 
1122     // special case the gopher protocol, disabled by default
1123     private static final String GOPHER = "gopher";
1124     private static final String ENABLE_GOPHER_PROP = "jdk.net.registerGopherProtocol";
1125     private static final boolean enableGopher = AccessController.doPrivileged(
1126         new PrivilegedAction<Boolean>() {
1127             public Boolean run() {
1128                 String prop = System.getProperty(ENABLE_GOPHER_PROP);
1129                 return prop == null ? false :
1130                    (prop.equalsIgnoreCase("false") ? false : true);
1131              }
1132         });
1133 
1134     // package name of the JDK implementation protocol handlers
1135     private static final String JDK_PACKAGE_PREFIX =  "sun.net.www.protocol";
1136 
1137     /**
1138      * Returns the Stream Handler.
1139      * @param protocol the protocol to use
1140      */
1141     static URLStreamHandler getURLStreamHandler(String protocol) {
1142 
1143         URLStreamHandler handler = (URLStreamHandler)handlers.get(protocol);
1144         if (handler == null) {
1145 
1146             boolean checkedWithFactory = false;
1147 
1148             // Use the factory (if any)
1149             if (factory != null) {
1150                 handler = factory.createURLStreamHandler(protocol);
1151                 checkedWithFactory = true;
1152             }
1153 
1154             // Try java protocol handler
1155             if (handler == null) {
1156                 String packagePrefixList = null;
1157 
1158                 packagePrefixList
1159                     = java.security.AccessController.doPrivileged(
1160                     new sun.security.action.GetPropertyAction(
1161                         protocolPathProp,""));
1162                 if (packagePrefixList != "") {
1163                     packagePrefixList += "|";


1170                 StringTokenizer packagePrefixIter =
1171                     new StringTokenizer(packagePrefixList, "|");
1172 
1173                 while (handler == null &&
1174                        packagePrefixIter.hasMoreTokens()) {
1175 
1176                     String packagePrefix =
1177                       packagePrefixIter.nextToken().trim();
1178 
1179                     // do not try to instantiate the JDK gopher handler
1180                     // unless the system property had been explicitly set
1181                     if (protocol.equalsIgnoreCase(GOPHER) &&
1182                         packagePrefix.equals(JDK_PACKAGE_PREFIX) &&
1183                         !enableGopher) {
1184                             continue;
1185                     }
1186 
1187                     try {
1188                         String clsName = packagePrefix + "." + protocol +
1189                           ".Handler";
1190                         Class cls = null;
1191                         try {
1192                             cls = Class.forName(clsName);
1193                         } catch (ClassNotFoundException e) {
1194                             ClassLoader cl = ClassLoader.getSystemClassLoader();
1195                             if (cl != null) {
1196                                 cls = cl.loadClass(clsName);
1197                             }
1198                         }
1199                         if (cls != null) {
1200                             handler  =
1201                               (URLStreamHandler)cls.newInstance();
1202                         }
1203                     } catch (Exception e) {
1204                         // any number of exceptions can get thrown here
1205                     }
1206                 }
1207             }
1208 
1209             synchronized (streamHandlerLock) {
1210 
1211                 URLStreamHandler handler2 = null;
1212 
1213                 // Check again with hashtable just in case another
1214                 // thread created a handler since we last checked
1215                 handler2 = (URLStreamHandler)handlers.get(protocol);
1216 
1217                 if (handler2 != null) {
1218                     return handler2;
1219                 }
1220 
1221                 // Check with factory if another thread set a
1222                 // factory since our last check
1223                 if (!checkedWithFactory && factory != null) {
1224                     handler2 = factory.createURLStreamHandler(protocol);
1225                 }
1226 
1227                 if (handler2 != null) {
1228                     // The handler from the factory must be given more
1229                     // importance. Discard the default handler that
1230                     // this thread created.
1231                     handler = handler2;
1232                 }
1233 
1234                 // Insert this handler into the hashtable
1235                 if (handler != null) {




1099      * @see        java.net.URLStreamHandlerFactory
1100      * @see        SecurityManager#checkSetFactory
1101      */
1102     public static void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) {
1103         synchronized (streamHandlerLock) {
1104             if (factory != null) {
1105                 throw new Error("factory already defined");
1106             }
1107             SecurityManager security = System.getSecurityManager();
1108             if (security != null) {
1109                 security.checkSetFactory();
1110             }
1111             handlers.clear();
1112             factory = fac;
1113         }
1114     }
1115 
1116     /**
1117      * A table of protocol handlers.
1118      */
1119     static Hashtable<String,URLStreamHandler> handlers = new Hashtable<String,URLStreamHandler>();
1120     private static Object streamHandlerLock = new Object();
1121 
1122     // special case the gopher protocol, disabled by default
1123     private static final String GOPHER = "gopher";
1124     private static final String ENABLE_GOPHER_PROP = "jdk.net.registerGopherProtocol";
1125     private static final boolean enableGopher = AccessController.doPrivileged(
1126         new PrivilegedAction<Boolean>() {
1127             public Boolean run() {
1128                 String prop = System.getProperty(ENABLE_GOPHER_PROP);
1129                 return prop == null ? false :
1130                    (prop.equalsIgnoreCase("false") ? false : true);
1131              }
1132         });
1133 
1134     // package name of the JDK implementation protocol handlers
1135     private static final String JDK_PACKAGE_PREFIX =  "sun.net.www.protocol";
1136 
1137     /**
1138      * Returns the Stream Handler.
1139      * @param protocol the protocol to use
1140      */
1141     static URLStreamHandler getURLStreamHandler(String protocol) {
1142 
1143         URLStreamHandler handler = handlers.get(protocol);
1144         if (handler == null) {
1145 
1146             boolean checkedWithFactory = false;
1147 
1148             // Use the factory (if any)
1149             if (factory != null) {
1150                 handler = factory.createURLStreamHandler(protocol);
1151                 checkedWithFactory = true;
1152             }
1153 
1154             // Try java protocol handler
1155             if (handler == null) {
1156                 String packagePrefixList = null;
1157 
1158                 packagePrefixList
1159                     = java.security.AccessController.doPrivileged(
1160                     new sun.security.action.GetPropertyAction(
1161                         protocolPathProp,""));
1162                 if (packagePrefixList != "") {
1163                     packagePrefixList += "|";


1170                 StringTokenizer packagePrefixIter =
1171                     new StringTokenizer(packagePrefixList, "|");
1172 
1173                 while (handler == null &&
1174                        packagePrefixIter.hasMoreTokens()) {
1175 
1176                     String packagePrefix =
1177                       packagePrefixIter.nextToken().trim();
1178 
1179                     // do not try to instantiate the JDK gopher handler
1180                     // unless the system property had been explicitly set
1181                     if (protocol.equalsIgnoreCase(GOPHER) &&
1182                         packagePrefix.equals(JDK_PACKAGE_PREFIX) &&
1183                         !enableGopher) {
1184                             continue;
1185                     }
1186 
1187                     try {
1188                         String clsName = packagePrefix + "." + protocol +
1189                           ".Handler";
1190                         Class<?> cls = null;
1191                         try {
1192                             cls = Class.forName(clsName);
1193                         } catch (ClassNotFoundException e) {
1194                             ClassLoader cl = ClassLoader.getSystemClassLoader();
1195                             if (cl != null) {
1196                                 cls = cl.loadClass(clsName);
1197                             }
1198                         }
1199                         if (cls != null) {
1200                             handler  =
1201                               (URLStreamHandler)cls.newInstance();
1202                         }
1203                     } catch (Exception e) {
1204                         // any number of exceptions can get thrown here
1205                     }
1206                 }
1207             }
1208 
1209             synchronized (streamHandlerLock) {
1210 
1211                 URLStreamHandler handler2 = null;
1212 
1213                 // Check again with hashtable just in case another
1214                 // thread created a handler since we last checked
1215                 handler2 = handlers.get(protocol);
1216 
1217                 if (handler2 != null) {
1218                     return handler2;
1219                 }
1220 
1221                 // Check with factory if another thread set a
1222                 // factory since our last check
1223                 if (!checkedWithFactory && factory != null) {
1224                     handler2 = factory.createURLStreamHandler(protocol);
1225                 }
1226 
1227                 if (handler2 != null) {
1228                     // The handler from the factory must be given more
1229                     // importance. Discard the default handler that
1230                     // this thread created.
1231                     handler = handler2;
1232                 }
1233 
1234                 // Insert this handler into the hashtable
1235                 if (handler != null) {


< prev index next >