jtulach commented on code in PR #44:
URL: https://github.com/apache/netbeans-jackpot30/pull/44#discussion_r3323269061


##########
cmdline/lib/src/org/netbeans/modules/jackpot30/cmdline/lib/Utils.java:
##########
@@ -98,51 +98,30 @@ public static String categoryName(String id, Map<String, 
String> id2DisplayName)
 
     //copied from BootClassPathUtil:
     public static ClassPath createDefaultBootClassPath() {
-        String cp = System.getProperty("sun.boot.class.path");
-        if (cp != null) {
-            List<URL> urls = new ArrayList<>();
-            String[] paths = 
cp.split(Pattern.quote(System.getProperty("path.separator")));
-            for (String path : paths) {
-                File f = new File(path);
-
-                if (!f.canRead())
-                    continue;
-
-                FileObject fo = FileUtil.toFileObject(f);
-                if (FileUtil.isArchiveFile(fo)) {
-                    fo = FileUtil.getArchiveRoot(fo);
-                }
-                if (fo != null) {
-                    urls.add(fo.toURL());
-                }
-            }
-            return ClassPathSupport.createClassPath((URL[])urls.toArray(new 
URL[0]));
-        } else {
-            try {
-                
Class.forName("org.netbeans.ProxyURLStreamHandlerFactory").getMethod("register")
-                                                                          
.invoke(null);
-            } catch (ClassNotFoundException | NoSuchMethodException |
-                     SecurityException | IllegalAccessException |
-                    IllegalArgumentException | InvocationTargetException ex) {
-                throw new IllegalStateException(ex);
-            }
-            final List<PathResourceImplementation> modules = new ArrayList<>();
-            final File installDir = new File(System.getProperty("java.home"));
-            final URI imageURI = getImageURI(installDir);
-            try {
-                final FileObject jrtRoot = 
URLMapper.findFileObject(imageURI.toURL());
-                final FileObject root = getModulesRoot(jrtRoot);
-                for (FileObject module : root.getChildren()) {
-                    
modules.add(ClassPathSupport.createResource(module.toURL()));
-                }
-            } catch (MalformedURLException e) {
-                throw new IllegalStateException(e);
-            }
-            if (modules.isEmpty()) {
-                throw new IllegalStateException("No modules!");
+        try {
+            
Class.forName("org.netbeans.ProxyURLStreamHandlerFactory").getMethod("register")

Review Comment:
   Nasty.
   
   ### Why?
   
   Why this is needed? To provide special support for protocols like `nbfs`? Or 
to override support for standard protocols like `jar`?
   
   ### Fix
   
   Shalln't we (finally) have a way to register the factory in a more standard 
way, not using reflection like this?
   
   - according to 
[javadoc](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/URL.html#%3Cinit%3E(java.lang.String,java.lang.String,int,java.lang.String))
 _"the 
[ServiceLoader](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/ServiceLoader.html)
 mechanism is used to locate 
[URLStreamHandlerProvider](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/spi/URLStreamHandlerProvider.html)
 implementations using the system class loader."_
   - why isn't `ProxyURLStreamHandlerFactory` registered in service loader as 
[URLStreamHandlerProvider](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/net/spi/URLStreamHandlerProvider.html)
 then?
   
   If it was, then this code could be replaced by `for (var p : 
ServiceLoader.load(URLStreamHandlerProvider.class)) { }` - e.g. just by 
iterating over public classes the support could be enabled.
   
   Or am I over simplifying the problem?



-- 
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