Prevent recursive loading of ZipResource class closure
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 11 May 2014 08:08:17 +0200
branchclosure
changeset 15547ba27baf5f3f
parent 1553 18ad02fdd1ef
child 1555 71e68f7ed23f
Prevent recursive loading of ZipResource class
rt/vm/src/main/java/org/apidesign/vm4brwsr/ClassPath.java
     1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ClassPath.java	Sun May 11 08:05:59 2014 +0200
     1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ClassPath.java	Sun May 11 08:08:17 2014 +0200
     1.3 @@ -40,12 +40,14 @@
     1.4      @JavaScriptBody(args = { "arr", "index", "value" }, body = "arr[index] = value; return value;")
     1.5      private static native Object set(Object arr, int index, Object value);
     1.6      
     1.7 +    private static boolean doingToZip;
     1.8      public static byte[] loadFromCp(Object classpath, String res, int skip) 
     1.9      throws IOException, ClassNotFoundException {
    1.10          for (int i = 0; i < length(classpath); i++) {
    1.11              Object c = at(classpath, i);
    1.12 -            if (c instanceof String) {
    1.13 +            if (c instanceof String && !doingToZip) {
    1.14                  try {
    1.15 +                    doingToZip = true;
    1.16                      String url = (String)c;
    1.17                      final Bck2Brwsr.Resources z = toZip(url);
    1.18                      c = set(classpath, i, z);
    1.19 @@ -59,6 +61,8 @@
    1.20                  } catch (IOException ex) {
    1.21                      set(classpath, i, ex);
    1.22                      log("Cannot load " + c + " - " + ex.getClass().getName() + ":" + ex.getMessage());
    1.23 +                } finally {
    1.24 +                    doingToZip = false;
    1.25                  }
    1.26              }
    1.27              if (res != null) {
    1.28 @@ -117,7 +121,7 @@
    1.29  
    1.30      @JavaScriptBody(args = { "arr", "len" }, body = "while (arr.length < len) arr.push(null); return arr;")
    1.31      private static native Object enlargeArray(Object arr, int len);
    1.32 -    
    1.33 +
    1.34      private static Bck2Brwsr.Resources toZip(String path) throws IOException {
    1.35          URL u = new URL(path);
    1.36          byte[] zipData = (byte[]) u.getContent(new Class[]{byte[].class});