Skip to content

Commit

Permalink
[CBRD-24557] Jar is not loaded by Java SP ClassLoader (#3945) (#3950)
Browse files Browse the repository at this point in the history
  • Loading branch information
hgryoo authored Nov 16, 2022
1 parent 4ea991d commit d14dca5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jsp/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</target>

<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${classes.dir}" source="1.6" target="1.6" includeantruntime="no" encoding="UTF-8" debug="true" classpathref="runtime.path">
<javac srcdir="${src.dir}" destdir="${classes.dir}" source="1.8" target="1.8" includeantruntime="no" encoding="UTF-8" debug="true" classpathref="runtime.path">
<include name="**/*.java"/>
</javac>
</target>
Expand Down
22 changes: 21 additions & 1 deletion src/jsp/com/cubrid/jsp/StoredProcedureClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
package com.cubrid.jsp;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.stream.Stream;

public class StoredProcedureClassLoader extends URLClassLoader {
private static volatile StoredProcedureClassLoader instance = null;
Expand All @@ -65,12 +68,29 @@ private StoredProcedureClassLoader() {
private void init() {
try {
addURL(root.toUri().toURL());
initJar();
lastModified = getLastModifiedTime(root);
} catch (IOException e) {
} catch (Exception e) {
Server.log(e);
}
}

private void initJar() throws IOException {
try (Stream<Path> files = Files.list(root)) {
files.filter((file) -> !Files.isDirectory(file) && (file.toString().endsWith(".jar")))
.forEach(
jar -> {
try {
addURL(jar.toUri().toURL());
} catch (MalformedURLException e) {
Server.log(e);
}
});
} catch (NoSuchFileException e) {
// ignore
}
}

public Class<?> loadClass(String name) throws ClassNotFoundException {
try {
if (!isModified()) {
Expand Down
7 changes: 6 additions & 1 deletion src/jsp/com/cubrid/jsp/TargetMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ private static void initdescriptorMap() {

public Method getMethod()
throws SecurityException, NoSuchMethodException, ClassNotFoundException {
return getClass(className).getMethod(methodName, argsTypes);
Class<?> c = getClass(className);
if (c == null) {
throw new ClassNotFoundException (className);
}
Method m = c.getMethod(methodName, argsTypes);
return m;
}

public Class<?>[] getArgsTypes() {
Expand Down

0 comments on commit d14dca5

Please sign in to comment.