/hg/icedtea-web: Saving/Loading of icon made resistent against U...
jvanek at icedtea.classpath.org
jvanek at icedtea.classpath.org
Wed Feb 11 08:57:14 UTC 2015
changeset 6d7f7e0e3829 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=6d7f7e0e3829
author: Jiri Vanek <jvanek at redhat.com>
date: Wed Feb 11 09:56:37 2015 +0100
Saving/Loading of icon made resistent against URLs with invalid/without target
* netx/net/sourceforge/jnlp/cache/CacheUtil.java: getCachedResource split into getCachedResourceFile and getCachedResourceURL (which is jsut transforming file from getCachedResourceFile to URL)
* netx/net/sourceforge/jnlp/util/XDesktopEntry.java: (cacheIcon) calls to getCachedResource replaced by calls to getCachedResourceURL and added nullchecks. New method of cantCache to unify NonFileProtocolException throw.
diffstat:
ChangeLog | 12 +++++++++-
netx/net/sourceforge/jnlp/cache/CacheUtil.java | 27 +++++++++++++++++++---
netx/net/sourceforge/jnlp/util/XDesktopEntry.java | 24 +++++++++++++++-----
3 files changed, 52 insertions(+), 11 deletions(-)
diffs (115 lines):
diff -r 95c4a59a6b8d -r 6d7f7e0e3829 ChangeLog
--- a/ChangeLog Mon Feb 09 16:44:15 2015 -0500
+++ b/ChangeLog Wed Feb 11 09:56:37 2015 +0100
@@ -1,4 +1,14 @@
-2014-02-09 Jie Kang <jkang at redhat.com>
+2015-02-11 Jiri Vanek <jvanek at redhat.com>
+
+ Saving/Loading of icon made resistent against URLs with invalid/without target
+ * netx/net/sourceforge/jnlp/cache/CacheUtil.java: getCachedResource split
+ into getCachedResourceFile and getCachedResourceURL (which is jsut transforming
+ file from getCachedResourceFile to URL)
+ * netx/net/sourceforge/jnlp/util/XDesktopEntry.java: (cacheIcon) calls to
+ getCachedResource replaced by calls to getCachedResourceURL and added null
+ checks. New method of cantCache to unify NonFileProtocolException throw.
+
+2015-02-09 Jie Kang <jkang at redhat.com>
Fix javascript url error in JSToJSet reproducer.
* tests/reproducers/simple/JSToJSet/resources/JSToJSet.html: added quotes
diff -r 95c4a59a6b8d -r 6d7f7e0e3829 netx/net/sourceforge/jnlp/cache/CacheUtil.java
--- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java Mon Feb 09 16:44:15 2015 -0500
+++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java Wed Feb 11 09:56:37 2015 +0100
@@ -70,19 +70,38 @@
*
* @param location location of the resource
* @param version the version, or {@code null}
+ * @param policy how to handle update
* @return either the location in the cache or the original location
*/
- public static URL getCachedResource(URL location, Version version, UpdatePolicy policy) {
- ResourceTracker rt = new ResourceTracker();
- rt.addResource(location, version, null, policy);
+ public static URL getCachedResourceURL(URL location, Version version, UpdatePolicy policy) {
try {
- File f = rt.getCacheFile(location);
+ File f = getCachedResourceFile(location, version, policy);
+ //url was ponting to nowhere eg 404
+ if (f == null){
+ //originally f.toUrl was throwing NPE
+ return null;
+ //returning null seems to be better
+ }
// TODO: Should be toURI().toURL()
return f.toURL();
} catch (MalformedURLException ex) {
return location;
}
}
+
+ /**
+ * This is returning File object of cached resource originally from URL
+ * @param location original location of blob
+ * @param version
+ * @param policy
+ * @return location in ITW cache on filesystem
+ */
+ public static File getCachedResourceFile(URL location, Version version, UpdatePolicy policy) {
+ ResourceTracker rt = new ResourceTracker();
+ rt.addResource(location, version, null, policy);
+ File f = rt.getCacheFile(location);
+ return f;
+ }
/**
* Returns the Permission object necessary to access the
diff -r 95c4a59a6b8d -r 6d7f7e0e3829 netx/net/sourceforge/jnlp/util/XDesktopEntry.java
--- a/netx/net/sourceforge/jnlp/util/XDesktopEntry.java Mon Feb 09 16:44:15 2015 -0500
+++ b/netx/net/sourceforge/jnlp/util/XDesktopEntry.java Wed Feb 11 09:56:37 2015 +0100
@@ -431,10 +431,14 @@
String location = null;
if (uiconLocation != null) {
- location = CacheUtil.getCachedResource(uiconLocation, null, UpdatePolicy.SESSION)
- .toString();
+ //this throws npe, if url (specified in jnlp) points to 404
+ URL urlLocation = CacheUtil.getCachedResourceURL(uiconLocation, null, UpdatePolicy.SESSION);
+ if (urlLocation == null) {
+ cantCache();
+ }
+ location = urlLocation.toString();
if (!location.startsWith("file:")) {
- throw new NonFileProtocolException("Unable to cache icon");
+ cantCache();
}
} else {
//try favicon.ico
@@ -445,10 +449,14 @@
file.getCodeBase().getPort(),
"/" + FAVICON);
JNLPFile.openURL(favico, null, UpdatePolicy.ALWAYS);
- location = CacheUtil.getCachedResource(favico, null, UpdatePolicy.SESSION)
- .toString();
+ //this MAY throw npe, if url (specified in jnlp) points to 404
+ URL urlLocation = CacheUtil.getCachedResourceURL(favico, null, UpdatePolicy.SESSION);
+ if (urlLocation == null) {
+ cantCache();
+ }
+ location = urlLocation.toString();
if (!location.startsWith("file:")) {
- throw new NonFileProtocolException("Unable to cache icon");
+ cantCache();
}
} catch (IOException ex) {
//favicon 404 or similar
@@ -474,6 +482,10 @@
}
}
+ private void cantCache() throws NonFileProtocolException {
+ throw new NonFileProtocolException("Unable to cache icon");
+ }
+
private String getDesktopIconName() {
return sanitize(file.createJnlpTitle());
}
More information about the distro-pkg-dev
mailing list