changeset 758:cde47c89edc4

8129956: jaxp: CodeSource.getLocation() might return null Reviewed-by: lancea
author dfuchs
date Fri, 26 Jun 2015 17:26:48 +0200
parents fcb2520aef55
children a3200b88f259
files src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java
diffstat 2 files changed, 52 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java	Thu Jun 25 20:06:37 2015 +0200
+++ b/src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java	Fri Jun 26 17:26:48 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2015, 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
@@ -25,11 +25,9 @@
 
 package javax.xml.validation;
 
-import java.io.IOException;
 import java.net.URL;
 import java.security.*;
 import java.io.*;
-import java.util.*;
 
 /**
  * This class is duplicated for each JAXP subpackage so keep it in sync.
@@ -42,9 +40,10 @@
 
 
     ClassLoader getContextClassLoader() {
-        return (ClassLoader)
-        AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
+        return
+        AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+            @Override
+            public ClassLoader run() {
                 ClassLoader cl = null;
                 //try {
                 cl = Thread.currentThread().getContextClassLoader();
@@ -57,9 +56,9 @@
     }
 
     String getSystemProperty(final String propName) {
-        return (String)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
+        return AccessController.doPrivileged(new PrivilegedAction<String>() {
+                @Override
+                public String run() {
                     return System.getProperty(propName);
                 }
             });
@@ -69,9 +68,10 @@
         throws FileNotFoundException
     {
         try {
-            return (FileInputStream)
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws FileNotFoundException {
+            return AccessController.doPrivileged(
+                new PrivilegedExceptionAction<FileInputStream>() {
+                    @Override
+                    public FileInputStream run() throws FileNotFoundException {
                         return new FileInputStream(file);
                     }
                 });
@@ -80,42 +80,29 @@
         }
     }
 
-    InputStream getURLInputStream(final URL url)
-        throws IOException
-    {
-        try {
-            return (InputStream)
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws IOException {
-                        return url.openStream();
-                    }
-                });
-        } catch (PrivilegedActionException e) {
-            throw (IOException)e.getException();
-        }
-    }
-
     // Used for debugging purposes
     String getClassSource(Class<?> cls) {
         return AccessController.doPrivileged(new PrivilegedAction<String>() {
+            @Override
             public String run() {
-               CodeSource cs = cls.getProtectionDomain().getCodeSource();
-               if (cs != null) {
-                    return cs.getLocation().toString();
-               } else {
+                CodeSource cs = cls.getProtectionDomain().getCodeSource();
+                if (cs != null) {
+                   URL loc = cs.getLocation();
+                   return loc != null ? loc.toString() : "(no location)";
+                } else {
                    return "(no code source)";
-               }
+                }
             }
         });
     }
 
     boolean doesFileExist(final File f) {
-        return ((Boolean)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Boolean(f.exists());
-                }
-            })).booleanValue();
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+            @Override
+            public Boolean run() {
+                return f.exists();
+            }
+        });
     }
 
 }
--- a/src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java	Thu Jun 25 20:06:37 2015 +0200
+++ b/src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java	Fri Jun 26 17:26:48 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2015, 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
@@ -28,7 +28,6 @@
 import java.net.URL;
 import java.security.*;
 import java.io.*;
-import java.util.*;
 
 /**
  * This class is duplicated for each JAXP subpackage so keep it in sync.
@@ -41,9 +40,9 @@
 
 
     ClassLoader getContextClassLoader() {
-        return (ClassLoader)
-                AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
+        return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+            @Override
+            public ClassLoader run() {
                 ClassLoader cl = null;
                 try {
                     cl = Thread.currentThread().getContextClassLoader();
@@ -54,21 +53,22 @@
     }
 
     String getSystemProperty(final String propName) {
-        return (String)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return System.getProperty(propName);
-                }
-            });
+        return AccessController.doPrivileged(new PrivilegedAction<String>() {
+            @Override
+            public String run() {
+                return System.getProperty(propName);
+            }
+        });
     }
 
     FileInputStream getFileInputStream(final File file)
         throws FileNotFoundException
     {
         try {
-            return (FileInputStream)
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws FileNotFoundException {
+            return AccessController.doPrivileged(
+                new PrivilegedExceptionAction<FileInputStream>() {
+                    @Override
+                    public FileInputStream run() throws FileNotFoundException {
                         return new FileInputStream(file);
                     }
                 });
@@ -77,42 +77,29 @@
         }
     }
 
-    InputStream getURLInputStream(final URL url)
-        throws IOException
-    {
-        try {
-            return (InputStream)
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws IOException {
-                        return url.openStream();
-                    }
-                });
-        } catch (PrivilegedActionException e) {
-            throw (IOException)e.getException();
-        }
-    }
-
     // Used for debugging purposes
     String getClassSource(Class<?> cls) {
         return AccessController.doPrivileged(new PrivilegedAction<String>() {
+            @Override
             public String run() {
-               CodeSource cs = cls.getProtectionDomain().getCodeSource();
-               if (cs != null) {
-                    return cs.getLocation().toString();
-               } else {
+                CodeSource cs = cls.getProtectionDomain().getCodeSource();
+                if (cs != null) {
+                   URL loc = cs.getLocation();
+                   return loc != null ? loc.toString() : "(no location)";
+                } else {
                    return "(no code source)";
-               }
+                }
             }
         });
     }
 
     boolean doesFileExist(final File f) {
-        return ((Boolean)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Boolean(f.exists());
-                }
-            })).booleanValue();
+        return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+            @Override
+            public Boolean run() {
+                return f.exists();
+            }
+        });
     }
 
 }