# HG changeset patch # User dfuchs # Date 1435332408 -7200 # Node ID cde47c89edc4e479365d5d55298edac49fbb9358 # Parent fcb2520aef551f38e71417f92dff2d067847f5b5 8129956: jaxp: CodeSource.getLocation() might return null Reviewed-by: lancea diff -r fcb2520aef55 -r cde47c89edc4 src/java.xml/share/classes/javax/xml/validation/SecuritySupport.java --- 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() { + @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() { + @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() { + @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() { + @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() { + @Override + public Boolean run() { + return f.exists(); + } + }); } } diff -r fcb2520aef55 -r cde47c89edc4 src/java.xml/share/classes/javax/xml/xpath/SecuritySupport.java --- 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() { + @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() { + @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() { + @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() { + @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() { + @Override + public Boolean run() { + return f.exists(); + } + }); } }