当前位置:网站首页>Custom classloader that breaks parental delegation
Custom classloader that breaks parental delegation
2022-07-02 03:20:00 【Tianlong supreme】
Steps to break parental delegation :
1、 Inherit ClassLoader
2、 rewrite loadClass、findClass
Code implementation :
package ljxwtl;
import org.apache.commons.io.IOUtils;
import java.io.*;
/**
* @author: wtl
* @License: (C) Copyright 2022, wtl Corporation Limited.
* @Contact: [email protected]
* @Date: 2022/2/15 9:58 AM
* @Version: 1.0
* @Description:
*/
public class CustomClassLoader extends ClassLoader{
@Override
public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
synchronized (getClassLoadingLock(name)) {
// First, check if the class has already been loaded
Class<?> c = findLoadedClass(name);
if (c == null) {
if (!name.startsWith("ljxwtl")){
c = super.loadClass(name,resolve);
}
else{
// If still not found, then invoke findClass in order
// to find the class.
c = findClass(name);
}
}
if (resolve) {
resolveClass(c);
}
return c;
}
}
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
String classPath = name.replaceAll("\\.","/");
InputStream inputStream = CustomClassLoader.class.getResourceAsStream("/" + classPath + ".class");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
IOUtils.copy(inputStream,byteArrayOutputStream);
} catch (IOException e) {
e.printStackTrace();
}
byte[] classBytes = byteArrayOutputStream.toByteArray();
return defineClass(name,classBytes,0,classBytes.length);
}
}
边栏推荐
- halcon图像矫正
- ORA-01547、ORA-01194、ORA-01110
- JS introduction < 1 >
- What is hybrid web containers for SAP ui5
- 【JVM】创建对象的流程详解
- JDBC details
- How to develop digital collections? How to develop your own digital collections
- Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]
- Discrimination between sap Hana, s/4hana and SAP BTP
- Detailed explanation of the difference between Verilog process assignment
猜你喜欢

Force deduction daily question 540 A single element in an ordered array

Golang configure export goprivate to pull private library code

Cache processing scheme in high concurrency scenario

MySQL connection query and subquery
![[HCIA continuous update] overview of dynamic routing protocol](/img/03/83c883afb63b7c63f6879b5513bac3.jpg)
[HCIA continuous update] overview of dynamic routing protocol
![[C Advanced] brother Peng takes you to play with strings and memory functions](/img/95/ab1bb0b3fa0b99e32233a5ca5d42a4.jpg)
[C Advanced] brother Peng takes you to play with strings and memory functions

Detailed explanation of the difference between Verilog process assignment

JIT deep analysis

West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials

C reflection practice
随机推荐
Possible causes of runtime error
Framing in data transmission
venn圖取交集
Global and Chinese markets for hand hygiene monitoring systems 2022-2028: Research Report on technology, participants, trends, market size and share
Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes
What is hybrid web containers for SAP ui5
Docker installs canal and MySQL for simple testing and implementation of redis and MySQL cache consistency
C#聯合halcon脫離halcon環境以及各種報錯解决經曆
What is the binding path of SAP ui5
[golang] leetcode intermediate bracket generation & Full Permutation
SAML2.0 笔记(一)
小米青年工程师,本来只是去打个酱油
Global and Chinese market of handheld ultrasonic scanners 2022-2028: Research Report on technology, participants, trends, market size and share
Merge interval, linked list, array
Grpc快速实践
Baohong industry | 6 financial management models at different stages of life
tarjan2
表单自定义校验规则
浅谈线程池相关配置
MSI announced that its motherboard products will cancel all paper accessories