Questions tagged [java-assist]

19 questions
5
votes
0 answers

Java objects unnecessary promotion to old generation just after a minor gc causing memory fragmentation issues

We are facing a strange memory leak issue in our application. GC configuration: ParNew + CMS A certain type of Objects are getting promoted to old generation too early and causing severe fragmentation issues. Survivor had enough space to…
3
votes
2 answers

How to swap method bodies under Android

In pure Java, using intrumentation and java agents, there is a way to replace the body of a method at runtime. Unfrotunately java.lang.instrument.Instrumentation is not available under Android. I have checked all other alternatives, like the one…
Panayotis
  • 1,792
  • 23
  • 32
1
vote
0 answers

Android: Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 19 at 5

We're integrating the Hotfix Robust lib to my app. While running the app we're getting below error. We have set the compileOptions to Java8 version and also tried by adding Javaassist version 3.27.0-GA but no luck. Execution failed for task…
Mr. N.V.Rao
  • 1,082
  • 13
  • 27
1
vote
0 answers

Java Adding field and method to compiled class and reload using class loader

I would like to add field along with its getter/setter in compiled Java classes which is loaded in a Spring boot application. I was able to modify the class using JavaAssist and ASM. But the problem is it is not letting me reload the class after…
1
vote
1 answer

Javassist - Numeric operations in CtMethod method body throws java.lang.VerifyError

Please see below code of creating a class and method using javassist: public Class generateClass(String className, String methodName) throws CannotCompileException, NotFoundException { ClassPool pool = ClassPool.getDefault(); …
javaseeker
  • 73
  • 1
  • 9
1
vote
1 answer

In Javassist, how to set return type of method to java.lang.Double when creating dynamic method using CtMethod

I have to dynamically create a class and method at run time. I am using Javassist for this: The method that I want to dynamically create is: public Double formula1(FormulaAPI api) { return api.evaluate(\"L\"); } If I pass the entire above…
javaseeker
  • 73
  • 1
  • 9
1
vote
0 answers

How to get notified when a method from different JVM is executed and get handle to arguments

Is there a way to get notified when a method from a Different JVM is called. Dev Env: JDK8, Windows 10 (later on cloud for deployment). I have couple of Java applications running, One in App Server and another is standalone batch process. Whenever a…
Kedar
  • 11
  • 2
1
vote
1 answer

Errors modifying an existing class using JavaAssist

I'm working on the following CodeWars challenge : https://www.codewars.com/kata/hack-22/train/java Here's what I've written : public static Yossarian loophole() throws Throwable { ClassPool pool = ClassPool.getDefault(); //Loader cl = new…
Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
0
votes
1 answer

How do I replace a value in a method with ExprEditor?

I am trying to modify the value in the code from 2.0 to 1.0 with expreditor. Nested if statements under a method "alterSkill" if (player2.hasSleepBonus()) { advanceMultiplicator *= 2.0;} I've got a utility someone else wrote public static…
0
votes
0 answers

Maven MyBatis tests fail when running Java 8 project compiled with Java 11

I have a multi-module Maven project build / compiled using Java 8. I recently just installed OpenJDK 11 in an effort to upgrade the project to Java 11. Before actually updated any components, etc. I wanted to compile my Java 8 project as Java 8 but…
Ryan Griffith
  • 1,591
  • 17
  • 41
0
votes
1 answer

Powermock 1.6.4 with Javassist 3.24.0-GA produces javassist.CannotCompileException: by javassist.bytecode.BadBytecode

I am using below versions of powermock and junit with javaassist. Most of the test cases are working fine except few which are written for classes that uses CloseableHttpClient. I have tried different combinations of powermock + javaassist but…
Loren
  • 320
  • 1
  • 10
  • 25
0
votes
0 answers

Javaassist Catch Block e.printStackTrace

We have the below Javaassist Code to add printStackTrace() to a catch block present inside a 3rd party Class int position = catchBlocks[i].block().position(); int lineNumber =…
Sabari
  • 127
  • 1
  • 13
0
votes
0 answers

How can I capture the HTTP request and response using Instrumentation's Java API?

I am writing a -javaagent to capture the HTTP request and response using Java's Instrumentation API such as javassist/ asm. I could insert the code around the method but how can I capture if the method is about to make a HTTP call and capture the…
Vishrant
  • 15,456
  • 11
  • 71
  • 120
0
votes
0 answers

Exception in thread "main" java.lang.IllegalStateException: Failed to transform class with name

I am using JAVA 1.8 with the Javaassist version as 3.24.0 and power mock 1.7.4. I am facing this issue when I am including a class in @PrepareForTest.Here the MainClass class depends on serverCommunicator.class instance. public class MainClass …
priya
  • 1
  • 1
0
votes
1 answer

How to get correct line number of all methods using javaassist or any other api?

I'm not able to get a correct line of methods. Few are getting properly few are not. for (CtMethod declaredMethod : declaredMethods) { int methodLineNumber = declaredMethod.getMethodInfo().getLineNumber(0); } 1)What is the mistake? 2)In…
kumar
  • 11
  • 1
1
2