Comments (3)
@Littlenotch-Jacuzzi , I am getting
java.lang.SecurityException: Unsafe
at jdk.unsupported/sun.misc.Unsafe.getUnsafe(Unsafe.java:99)
at com.rits.cloning.Cloner.newInstance(Cloner.java:311)
at com.rits.cloning.Cloner$CloneObjectCloner.deepClone(Cloner.java:618)
at com.rits.cloning.Cloner.cloneInternal(Cloner.java:447)
at com.rits.cloning.Cloner.deepClone(Cloner.java:338)
at com.rits.tests.cloning.TestCloner.testNullInsteadOfCloneAnnotatedFields(TestCloner.java:555)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at junit.framework.TestCase.runTest(TestCase.java:177)
at junit.framework.TestCase.runBare(TestCase.java:142)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:130)
at junit.framework.TestSuite.runTest(TestSuite.java:241)
at junit.framework.TestSuite.run(TestSuite.java:236)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
if I replace objenesis with Unsafe
from cloning.
@kostaskougios
Yes, you can't directly call that method in Unsafe. I wrote a method to solve it:
private static Unsafe hackUnsafe() {
try {
Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
return (Unsafe) field.get(null);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Use this method to replace the Unsafe.getUnsafe() method.
from cloning.
Note that the efficiency of the Unsafe.allocateInstance() method is about 2000 times that of Objenesis. But the instantiated objects has not gone any initialization, and the fields in these objects are all null(reference type) or default values(basic type).
from cloning.
Related Issues (20)
- NoClassDefFoundError HOT 1
- Invalid clone result for List.of() and Set.of() objects on JDK15 HOT 2
- illegal reflective access HOT 1
- Java 16 Support HOT 16
- download url in wiki/downloads.md is 404 HOT 1
- Avoid throwing and catching ClassNotFoundException for SubList and RandomAccessSubList
- Bump objenesis to 3.2
- Illegal reflective access by com.rits.cloning.Cloner$CloneObjectCloner for Timestamp.nanos HOT 1
- why use "I" of interface prefix HOT 3
- Java module
- Version 1.11 not available at Maven Repository? HOT 3
- java.util.Date cloning error HOT 2
- java.lang.IllegalArgumentException: Can not set final java.lang.String field org.apache.logging.log4j.Level.name to org.apache.logging.log4j.Level
- java.lang.NoClassDefFoundError:
- Objenesis dependency version maintenance in this repo HOT 1
- Stackoverflow when deepclone an object with recursive references.
- Java 17 support for complex deep cloning HOT 2
- Custom cloning HOT 3
- Latest Release Update? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloning.