当前位置:网站首页>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);
}
}
边栏推荐
- Global and Chinese markets for hand hygiene monitoring systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Verilog timing control
- 2022-2028 global wood vacuum coating machine industry research and trend analysis report
- Mathematical calculation in real mode addressing
- Rotating frame target detection mmrotate v0.3.1 learning model
- Global and Chinese market of bone adhesives 2022-2028: Research Report on technology, participants, trends, market size and share
- Gradle notes
- Cache processing scheme in high concurrency scenario
- Use blocking or non blocking for streamline
- 旋转框目标检测mmrotate v0.3.1 学习模型
猜你喜欢

GB/T-2423. XX environmental test documents, including the latest documents

ThreadLocal详解

Mmsegmentation series training and reasoning their own data set (3)

MySQL advanced (Advanced) SQL statement (II)

One of the future trends of SAP ui5: embrace typescript

verilog 并行块实现

表单自定义校验规则

2022-2028 global soft capsule manufacturing machine industry research and trend analysis report
![[HCIA continuous update] working principle of OSPF Protocol](/img/bc/4eeb091c511fd563fb1e00c8c8881a.jpg)
[HCIA continuous update] working principle of OSPF Protocol

West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
随机推荐
Use blocking or non blocking for streamline
How to develop digital collections? How to develop your own digital collections
Golang configure export goprivate to pull private library code
Detailed explanation of the difference between Verilog process assignment
Start a business
GB/T-2423. XX environmental test documents, including the latest documents
On redis (II) -- cluster version
Intersection of Venn graph
Large screen visualization from bronze to the advanced king, you only need a "component reuse"!
32, 64, 128 bit system
Verilog 状态机
This article describes the step-by-step process of starting the NFT platform project
竞争与冒险 毛刺
MMSegmentation系列之训练与推理自己的数据集(三)
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
Work hard all day long and be alert at sunset
[golang] leetcode intermediate bracket generation & Full Permutation
Global and Chinese markets for infant care equipment, 2022-2028: Research Report on technology, participants, trends, market size and share
Uniapp uses canvas to generate posters and save them locally
Form custom verification rules