< prev index next >

src/java.base/share/classes/jdk/internal/loader/URLClassPath.java

Print this page
imported patch URLClasspath-simplify-constructor


 159             this.acc = acc;
 160     }
 161 
 162     public URLClassPath(URL[] urls, AccessControlContext acc) {
 163         this(urls, null, acc);
 164     }
 165 
 166     /**
 167      * Constructs a URLClassPath from a class path string.
 168      *
 169      * @param cp the class path string
 170      * @param skipEmptyElements indicates if empty elements are ignored or
 171      *        treated as the current working directory
 172      *
 173      * @apiNote Used to create the application class path.
 174      */
 175     URLClassPath(String cp, boolean skipEmptyElements) {
 176         ArrayList<URL> path = new ArrayList<>();
 177         if (cp != null) {
 178             // map each element of class path to a file URL
 179             int off = 0;
 180             int next;
 181             while ((next = cp.indexOf(File.pathSeparator, off)) != -1) {
 182                 String element = cp.substring(off, next);


 183                 if (element.length() > 0 || !skipEmptyElements) {
 184                     URL url = toFileURL(element);
 185                     if (url != null) path.add(url);
 186                 }
 187                 off = next + 1;
 188             }
 189 
 190             // remaining element
 191             String element = cp.substring(off);
 192             if (element.length() > 0 || !skipEmptyElements) {
 193                 URL url = toFileURL(element);
 194                 if (url != null) path.add(url);
 195             }
 196         }
 197 
 198         this.unopenedUrls = copyToArrayDeque(path);
 199         this.path = path;
 200         this.jarHandler = null;
 201         this.acc = null;
 202     }
 203 
 204     private <T> ArrayDeque<T> copyToArrayDeque(ArrayList<T> list) {
 205         // can't simplify to deque.addAll(list) or new ArrayDeque(list);
 206         // it's too early in the bootstrap to trigger use of lambdas
 207         int size = list.size();
 208         ArrayDeque<T> deque = new ArrayDeque<>(size);
 209         for (int i = 0; i < size; i++)
 210             deque.add(list.get(i));
 211         return deque;
 212     }
 213 
 214     public synchronized List<IOException> closeLoaders() {
 215         if (closed) {




 159             this.acc = acc;
 160     }
 161 
 162     public URLClassPath(URL[] urls, AccessControlContext acc) {
 163         this(urls, null, acc);
 164     }
 165 
 166     /**
 167      * Constructs a URLClassPath from a class path string.
 168      *
 169      * @param cp the class path string
 170      * @param skipEmptyElements indicates if empty elements are ignored or
 171      *        treated as the current working directory
 172      *
 173      * @apiNote Used to create the application class path.
 174      */
 175     URLClassPath(String cp, boolean skipEmptyElements) {
 176         ArrayList<URL> path = new ArrayList<>();
 177         if (cp != null) {
 178             // map each element of class path to a file URL
 179             int off = 0, next;
 180             do {
 181                 next = cp.indexOf(File.pathSeparator, off);
 182                 String element = (next == -1)
 183                     ? cp.substring(off)
 184                     : cp.substring(off, next);
 185                 if (element.length() > 0 || !skipEmptyElements) {
 186                     URL url = toFileURL(element);
 187                     if (url != null) path.add(url);
 188                 }
 189                 off = next + 1;
 190             } while (next != -1);







 191         }
 192 
 193         this.unopenedUrls = copyToArrayDeque(path);
 194         this.path = path;
 195         this.jarHandler = null;
 196         this.acc = null;
 197     }
 198 
 199     private <T> ArrayDeque<T> copyToArrayDeque(ArrayList<T> list) {
 200         // can't simplify to deque.addAll(list) or new ArrayDeque(list);
 201         // it's too early in the bootstrap to trigger use of lambdas
 202         int size = list.size();
 203         ArrayDeque<T> deque = new ArrayDeque<>(size);
 204         for (int i = 0; i < size; i++)
 205             deque.add(list.get(i));
 206         return deque;
 207     }
 208 
 209     public synchronized List<IOException> closeLoaders() {
 210         if (closed) {


< prev index next >