Merge pull request #5410 from khatwaniNikhil/BAEL-2288

Changes for BAEL-2288
This commit is contained in:
Loredana Crusoveanu 2018-10-09 21:28:39 +03:00 committed by GitHub
commit fb6a1a0855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -1,11 +1,14 @@
package com.baeldung.classloader; package com.baeldung.classloader;
import java.io.*; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
public class CustomClassLoader extends ClassLoader { public class CustomClassLoader extends ClassLoader {
@Override
public Class getClass(String name) throws ClassNotFoundException { public Class findClass(String name) throws ClassNotFoundException {
byte[] b = loadClassFromFile(name); byte[] b = loadClassFromFile(name);
return defineClass(name, b, 0, b.length); return defineClass(name, b, 0, b.length);
} }

View File

@ -11,7 +11,7 @@ public class CustomClassLoaderUnitTest {
public void customLoader() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException { public void customLoader() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
CustomClassLoader customClassLoader = new CustomClassLoader(); CustomClassLoader customClassLoader = new CustomClassLoader();
Class<?> c = customClassLoader.getClass(PrintClassLoader.class.getName()); Class<?> c = customClassLoader.findClass(PrintClassLoader.class.getName());
Object ob = c.newInstance(); Object ob = c.newInstance();