Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8260506: VersionHelper cleanup
Reviewed-by: alanb, dfuchs, aefimov
  • Loading branch information
cl4es committed Jan 28, 2021
1 parent a97aedf commit ecde52e
Showing 1 changed file with 14 additions and 28 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,13 +26,13 @@
package com.sun.naming.internal;

import javax.naming.NamingEnumeration;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
Expand Down Expand Up @@ -170,14 +170,12 @@ private static String resolveName(Class<?> c, String name) {
return name;
}
if (!name.startsWith("/")) {
while (c.isArray()) {
c = c.getComponentType();
}
String baseName = c.getName();
int index = baseName.lastIndexOf('.');
if (index != -1) {
name = baseName.substring(0, index).replace('.', '/')
+"/"+name;
if (!c.isPrimitive()) {
String baseName = c.getPackageName();
if (!baseName.isEmpty()) {
name = baseName.replace('.', '/') + "/"
+ name;
}
}
} else {
name = name.substring(1);
Expand All @@ -192,8 +190,7 @@ private static String resolveName(Class<?> c, String name) {
InputStream getResourceAsStream(Class<?> c, String name) {
PrivilegedAction<InputStream> act = () -> {
try {
Module m = c.getModule();
return c.getModule().getResourceAsStream(resolveName(c,name));
return c.getModule().getResourceAsStream(resolveName(c, name));
} catch (IOException x) {
return null;
}
Expand All @@ -214,9 +211,7 @@ InputStream getJavaHomeConfStream(String filename) {
if (javahome == null) {
return null;
}
String pathname = javahome + File.separator +
"conf" + File.separator + filename;
return new FileInputStream(pathname);
return Files.newInputStream(Path.of(javahome, "conf", filename));
} catch (Exception e) {
return null;
}
Expand Down Expand Up @@ -272,20 +267,11 @@ private static URL[] getUrlArray(String codebase)
throws MalformedURLException {
// Parse codebase into separate URLs
StringTokenizer parser = new StringTokenizer(codebase);
List<String> list = new ArrayList<>();
List<URL> list = new ArrayList<>();
while (parser.hasMoreTokens()) {
list.add(parser.nextToken());
}
String[] url = new String[list.size()];
for (int i = 0; i < url.length; i++) {
url[i] = list.get(i);
}

URL[] urlArray = new URL[url.length];
for (int i = 0; i < urlArray.length; i++) {
urlArray[i] = new URL(url[i]);
list.add(new URL(parser.nextToken()));
}
return urlArray;
return list.toArray(new URL[0]);
}

/**
Expand Down

1 comment on commit ecde52e

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.