Skip to content

Commit 781ee58

Browse files
hansonrhansonr
authored andcommitted
Assets fix for missing resource
1 parent 25ecbd2 commit 781ee58

File tree

1 file changed

+31
-3
lines changed
  • sources/net.sf.j2s.java.core/src/javajs/async

1 file changed

+31
-3
lines changed

sources/net.sf.j2s.java.core/src/javajs/async/Assets.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ public class Assets {
9696
}
9797
}
9898

99+
/**
100+
* track not-found resources
101+
*
102+
*/
103+
private static HashSet<String> nullResources;
104+
99105
private Map<String, Map<String, ZipEntry>> htZipContents = new HashMap<>();
100106

101107
private static boolean doCacheZipContents = true;
@@ -229,8 +235,13 @@ public static void add(String name, String zipFile, String path) {
229235
public static boolean hasLoaded(String name) {
230236
return loadedAssets.contains(name);
231237
}
232-
238+
239+
/**
240+
* Completely reset the assets data.
241+
*
242+
*/
233243
public static void reset() {
244+
nullResources = null;
234245
getInstance().htZipContents.clear();
235246
getInstance().assetsByPath.clear();
236247
getInstance().sortedList = new String[0];
@@ -429,14 +440,17 @@ private URL _getURLFromPath(String fullPath, boolean zipOnly) {
429440
}
430441

431442
public static ZipEntry findZipEntry(URL url) {
443+
if (url == null)
444+
return null;
432445
String[] parts = getJarURLParts(url.toString());
433446
if (parts == null || parts[0] == null || parts[1].length() == 0)
434447
return null;
435448
return findZipEntry(parts[0], parts[1]);
436449
}
437450

438451
public static ZipEntry findZipEntry(String zipFile, String fileName) {
439-
return getZipContents(zipFile).get(fileName);
452+
Map<String, ZipEntry> map = getZipContents(zipFile);
453+
return (map == null ? null : map.get(fileName));
440454
}
441455

442456
/**
@@ -449,7 +463,20 @@ public static Map<String, ZipEntry> getZipContents(String zipPath) {
449463
return getInstance()._getZipContents(zipPath);
450464
}
451465

466+
public static boolean notFound(String zipPath) {
467+
return (nullResources != null && nullResources.contains(zipPath));
468+
}
469+
470+
public static void setNotFound(String zipPath) {
471+
if (nullResources == null) {
472+
nullResources = new HashSet<>();
473+
}
474+
nullResources.add(zipPath);
475+
}
476+
452477
private Map<String, ZipEntry> _getZipContents(String zipPath) {
478+
if (notFound(zipPath))
479+
return null;
453480
URL url = getURLWithCachedBytes(zipPath); // BH carry over bytes if we have them already
454481
Map<String, ZipEntry> fileNames = htZipContents.get(url.toString());
455482
if (fileNames != null)
@@ -458,7 +485,8 @@ private Map<String, ZipEntry> _getZipContents(String zipPath) {
458485
// Scan URL zip stream for files.
459486
return readZipContents(url.openStream(), url);
460487
} catch (Exception ex) {
461-
ex.printStackTrace();
488+
System.err.println("Assets: " + zipPath + " could not be opened");
489+
setNotFound(zipPath);
462490
return null;
463491
}
464492
}

0 commit comments

Comments
 (0)