Skip to content

Commit

Permalink
eclipse-ee4j#1507: Failing to create entity manager when running an a…
Browse files Browse the repository at this point in the history
…pp using module path

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Jun 2, 2022
1 parent f4deba4 commit 464108a
Showing 1 changed file with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -87,9 +87,8 @@ private static List<String[]> initializeNameToVendorPlatform(SessionLog logger)
if(_nameToVendorPlatform == null) {
_nameToVendorPlatform = new ArrayList<>();
try {
loadFromResource(_nameToVendorPlatform, VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME,
DBPlatformHelper.class.getClassLoader() );
} catch (IOException e) {
loadFromResource(_nameToVendorPlatform, VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME);
} catch (Throwable e) {
logger.log(SessionLog.WARNING, SessionLog.CONNECTION, "dbPlatformHelper_noMappingFound", VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME);
}
}
Expand Down Expand Up @@ -140,9 +139,9 @@ private static boolean matchPattern(String regExp, String target, SessionLog log
}

//-----Property Loading helper methods ----/
private static void loadFromResource(List<String[]> properties, String resourceName, ClassLoader classLoader)
private static void loadFromResource(List<String[]> properties, String resourceName)
throws IOException {
load(properties, resourceName, classLoader);
load(properties, resourceName);
}

/**
Expand All @@ -153,14 +152,11 @@ private static void loadFromResource(List<String[]> properties, String resourceN
* If loadFromFile is true, this is fully qualified path name to a file.
* param classLoader is ignored.
* If loadFromFile is false,this is resource name.
* @param classLoader The class loader that should be used to load the resource. If null,primordial
* class loader is used.
*/
private static void load(List<String[]> properties, final String resourceName,
final ClassLoader classLoader)
private static void load(List<String[]> properties, final String resourceName)
throws IOException {
try (BufferedReader bin = new BufferedReader(
new InputStreamReader(openResourceInputStream(resourceName,classLoader)))) {
new InputStreamReader(openResourceInputStream(resourceName)))) {
for (String line = bin.readLine(); line != null; line = bin.readLine()) {
String[] keyValue = validateLineForReturnAsKeyValueArray(line);
if (keyValue != null) {
Expand All @@ -173,16 +169,10 @@ private static void load(List<String[]> properties, final String resourceName,
/**
* Open resourceName as input stream inside doPriviledged block
*/
private static InputStream openResourceInputStream(final String resourceName, final ClassLoader classLoader) {
return PrivilegedAccessHelper.callDoPrivileged(
() -> {
if (classLoader != null) {
return classLoader.getResourceAsStream(resourceName);
} else {
return ClassLoader.getSystemResourceAsStream(resourceName);
}
}
);
private static InputStream openResourceInputStream(final String resourceName) throws IOException {
return PrivilegedAccessHelper.callDoPrivilegedWithException(
() -> DBPlatformHelper.class.getModule().getResourceAsStream(resourceName),
(ex) -> (IOException) ex);
}

private static String[] validateLineForReturnAsKeyValueArray(String line) {
Expand Down

0 comments on commit 464108a

Please sign in to comment.