mbien commented on code in PR #3860:
URL: https://github.com/apache/netbeans/pull/3860#discussion_r935455655


##########
platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java:
##########
@@ -574,13 +609,81 @@ protected URL doGetResource(String name) throws 
IOException  {
         @Override
         protected byte[] readClass(String path) throws IOException {
             try {
+                if (isMultiRelease() && RUNTIME_VERSION > BASE_VERSION) {
+                    int[] vers = getVersions();
+                    if (vers.length > 0) {
+                        for (int i = vers.length - 1; i >= 0; i--) {
+                            int version = vers[i];
+                            if (version > RUNTIME_VERSION) {
+                                continue;
+                            }
+                            if (version < BASE_VERSION) {
+                                break;
+                            }
+                            byte[] data = archive.getData(this, 
"META-INF/versions/" + version + "/" + path);
+                            if (data != null) {
+                                return data;
+                            }
+                        }
+                    }
+                }
                 return archive.getData(this, path);
             } catch (ZipException ex) {
                 dumpFiles(file, -1);
                 throw ex;
             }
         }
-        
+
+        private int[] getVersions() {
+            int[] ret;
+            if (versions != null && (ret = versions.get()) != null) {
+                return ret;
+            }
+            try {
+                JarFile src = getJarFile("versions");
+                Set<Integer> vers = new TreeSet<>();
+                Enumeration<JarEntry> en = src.entries();
+                while (en.hasMoreElements()) {
+                    JarEntry je = en.nextElement();
+                    if (je.isDirectory()) {
+                        String itm = je.getName();
+                        if (itm.startsWith("META-INF/versions/")) {
+                            String res = itm.substring(18);
+                            int idx = res.indexOf('/');
+                            if (idx > 0 && idx == res.length() - 1) {
+                                vers.add(Integer.parseInt(res.substring(0, 
idx)));
+                            }
+                        }
+                    }
+                }
+                ret = new int[vers.size()];
+                int i = 0;
+                for (Integer ver : vers) {
+                    ret[i++] = ver;
+                }
+                versions = new SoftReference<>(ret);
+                return ret;
+            } catch (ZipException x) { // Unix
+                if (warnedFiles.add(file)) {
+                    LOGGER.log(Level.INFO, "Cannot open " + file, x);
+                    dumpFiles(file, -1);
+                }
+            } catch (FileNotFoundException x) { // Windows
+                if (warnedFiles.add(file)) {
+                    LOGGER.log(Level.INFO, "Cannot open " + file, x);
+                    dumpFiles(file, -1);
+                }
+            } catch (IOException ioe) {
+                if (warnedFiles.add(file)) {
+                    LOGGER.log(Level.WARNING, "problems with " + file, ioe);
+                    dumpFiles(file, -1);
+                }

Review Comment:
   candidate for multi catch.
   
   if NumberFormatException isn't caught inside the loop, it should be caught 
here (see last inline comment).



##########
platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java:
##########
@@ -574,13 +609,81 @@ protected URL doGetResource(String name) throws 
IOException  {
         @Override
         protected byte[] readClass(String path) throws IOException {
             try {
+                if (isMultiRelease() && RUNTIME_VERSION > BASE_VERSION) {
+                    int[] vers = getVersions();
+                    if (vers.length > 0) {
+                        for (int i = vers.length - 1; i >= 0; i--) {
+                            int version = vers[i];
+                            if (version > RUNTIME_VERSION) {
+                                continue;
+                            }
+                            if (version < BASE_VERSION) {
+                                break;
+                            }
+                            byte[] data = archive.getData(this, 
"META-INF/versions/" + version + "/" + path);
+                            if (data != null) {
+                                return data;
+                            }
+                        }
+                    }
+                }
                 return archive.getData(this, path);
             } catch (ZipException ex) {
                 dumpFiles(file, -1);
                 throw ex;
             }
         }
-        
+
+        private int[] getVersions() {
+            int[] ret;
+            if (versions != null && (ret = versions.get()) != null) {
+                return ret;
+            }
+            try {
+                JarFile src = getJarFile("versions");
+                Set<Integer> vers = new TreeSet<>();
+                Enumeration<JarEntry> en = src.entries();
+                while (en.hasMoreElements()) {
+                    JarEntry je = en.nextElement();
+                    if (je.isDirectory()) {
+                        String itm = je.getName();
+                        if (itm.startsWith("META-INF/versions/")) {
+                            String res = itm.substring(18);
+                            int idx = res.indexOf('/');
+                            if (idx > 0 && idx == res.length() - 1) {
+                                vers.add(Integer.parseInt(res.substring(0, 
idx)));
+                            }
+                        }
+                    }
+                }
+                ret = new int[vers.size()];
+                int i = 0;
+                for (Integer ver : vers) {
+                    ret[i++] = ver;
+                }
+                versions = new SoftReference<>(ret);
+                return ret;
+            } catch (ZipException x) { // Unix
+                if (warnedFiles.add(file)) {
+                    LOGGER.log(Level.INFO, "Cannot open " + file, x);
+                    dumpFiles(file, -1);
+                }
+            } catch (FileNotFoundException x) { // Windows
+                if (warnedFiles.add(file)) {
+                    LOGGER.log(Level.INFO, "Cannot open " + file, x);
+                    dumpFiles(file, -1);
+                }
+            } catch (IOException ioe) {
+                if (warnedFiles.add(file)) {
+                    LOGGER.log(Level.WARNING, "problems with " + file, ioe);
+                    dumpFiles(file, -1);
+                }

Review Comment:
   candidate for multi catch.
   
   if NumberFormatException isn't caught inside the loop, it should be caught 
here (see other inline comment).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to