Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11239)

Unified Diff: compiler/java/com/google/dart/compiler/UrlSource.java

Issue 10389206: Issue 3123. Catch exceptions in Source.exists()/initProperties() (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilation2Test.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/UrlSource.java
diff --git a/compiler/java/com/google/dart/compiler/UrlSource.java b/compiler/java/com/google/dart/compiler/UrlSource.java
index 317a38450031c30dfb70787f758c0bf8dbf2f547..b89e4b5ccff87b49d8828f64aa4c14cee28c8ff8 100644
--- a/compiler/java/com/google/dart/compiler/UrlSource.java
+++ b/compiler/java/com/google/dart/compiler/UrlSource.java
@@ -12,7 +12,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.JarURLConnection;
-import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
@@ -125,47 +124,48 @@ public abstract class UrlSource implements Source {
}
private void initProperties() {
- if (!propertiesInitialized) {
- synchronized(this) {
- if (!propertiesInitialized) {
- try {
- URI resolvedUri = BASE_URI.resolve(translatedUri);
- String scheme = resolvedUri.getScheme();
- if (scheme == null || FILE_PROTOCOL.equals(scheme)) {
- // Faster than using URLConnection
- File file = new File(resolvedUri);
- lastModified = file.lastModified();
- exists = file.exists();
- sourceFile = file;
- } else {
- try {
- URL url = translatedUri.toURL();
- if (JAR_PROTOCOL.equals(url.getProtocol())) {
- getJarEntryProperties(url);
- } else {
- /*
- * TODO(jbrosenberg): Flesh out the support for other
- * protocols, like http, etc. Note, calling
- * URLConnection.getLastModified() can be dangerous, some
- * URLConnection sub-classes don't have a way to close a
- * connection opened by this call. Return 0 for now.
- */
- lastModified = 0;
- // Default this to true for now.
- exists = true;
- }
- } catch (MalformedURLException e) {
- return;
- }
- }
- } finally {
- propertiesInitialized = true;
- }
+ synchronized (this) {
+ if (!propertiesInitialized) {
+ try {
+ initPropertiesEx();
+ } catch (Throwable e) {
Brian Wilkerson 2012/05/18 17:02:52 Is there a reason for expanding this to catch all
scheglov 2012/05/18 17:21:54 1. There is reason to throw and catch specific exc
+ } finally {
+ propertiesInitialized = true;
}
}
}
}
+ /**
+ * Implementation of {@link #initProperties()} which can throw exceptions.
+ */
+ private void initPropertiesEx() throws Exception {
+ URI resolvedUri = BASE_URI.resolve(translatedUri);
+ String scheme = resolvedUri.getScheme();
+ if (scheme == null || FILE_PROTOCOL.equals(scheme)) {
+ File file = new File(resolvedUri);
+ lastModified = file.lastModified();
+ exists = file.exists();
+ sourceFile = file;
+ } else {
+ URL url = translatedUri.toURL();
+ if (JAR_PROTOCOL.equals(url.getProtocol())) {
+ getJarEntryProperties(url);
+ } else {
+ /*
+ * TODO(jbrosenberg): Flesh out the support for other
+ * protocols, like http, etc. Note, calling
+ * URLConnection.getLastModified() can be dangerous, some
+ * URLConnection sub-classes don't have a way to close a
+ * connection opened by this call. Return 0 for now.
+ */
+ lastModified = 0;
+ // Default this to true for now.
+ exists = true;
+ }
+ }
+ }
+
private void getJarEntryProperties(URL url) {
try {
jarConn = (JarURLConnection) url.openConnection();
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/end2end/inc/IncrementalCompilation2Test.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698