Questions tagged [cglib]

CGLib (Code Generation Library) is a run time code generation library for the Java platform licensed under the Apache 2.0 license.

CGLib (Code Generation Library) is mainly used the generation of class proxies. This is achieved by creating subclasses at run time where method invocations are intercepted by user defined methods. Additionally, cglib offers different extension such as for example bean utilities. cglib is built on top of ASM.

Alternative code generation libraries for the JVM that are still under active development are:

401 questions
4
votes
2 answers

How to get eclipse debugger to skip $$EnhancerByCGLIB$$ methods?

I want to skip over methods generated by CGlib I have added $$EnhancerByCGLIB$$ to my eclipse step filters but still eclipse does not skip these, here is my configuration. How do I configure the step filter to get to skip any CGLib enhanced methods?…
ams
  • 60,316
  • 68
  • 200
  • 288
4
votes
2 answers

Automatically add unimplemented methods during compilation

I am trying find how to implement a hack that is similar to the Eclipse functionality "Add unimplemented methods". Instead of adding these methods while writing code, I would like to do this during compilation , generating a method body using a…
Miserable Variable
  • 28,432
  • 15
  • 72
  • 133
4
votes
1 answer

lambdaJ and ClassCastException on simple select

I run out of ideas, Google also did not help. Use case seems to be trivial but it fails with ClassCastException. I don't know what I am doing wrong. There's a simple method to return first element matching a given category, take a look. private…
wilu
  • 549
  • 1
  • 12
  • 26
4
votes
1 answer

Adding a field to Java class

Looked at using CGLib, ASM, BCEL (aspect) and Javassist to add a field to a class during runtime.... Just to get my head straight it looks like these bytecode manipulators don't update the actual class rather allow the user to only dump the…
Matthew Campbell
  • 1,864
  • 3
  • 24
  • 51
4
votes
2 answers

Superclass has no null constructors but no arguments were given. Spring Integration

I'm developing web application supported by Spring Integration. I'm using 1.0.4.RELEASE. I use CGLib proxies. I have a transactional message endpoint. Everything worked correctly, but I experimented a little bit with annotations. I use…
BartoszMiller
  • 1,245
  • 1
  • 15
  • 24
3
votes
2 answers

CGLIB, Spring and injection by constructor

I want to use cglib as my proxy mechanism for spring. problem is, i have some beans who have their dependecies injected by constructor and i cannot change this. CGLIB doesn't seem to like that very much and won't let me instantiate that bean. is…
ShinySpiderdude
  • 1,170
  • 4
  • 14
  • 18
3
votes
1 answer

Spring AOP: confirming CGLIB proxy behaviour

While referring to 'Pro Spring 2.5', I came across the following statement (page 193): For instance, the CGLIB proxy generates the appropriate bytecode to invoke any unadvised methods directly, dramatically reducing the overhead introduced by…
shrini1000
  • 7,038
  • 12
  • 59
  • 99
3
votes
1 answer

Can cglib be used to intercept direct field?

In the following test case , direct field t is not intercepted by CGLIB. So can I do it use CGLIB? public class Test { @Test public void testCGLib() { A a = (A) Enhancer.create(A.class, new Class[] {}, new B()); System.out.println(a.t); …
jackalope
  • 1,554
  • 3
  • 17
  • 37
3
votes
3 answers

Dynamically editing/creating classes in Java Android

I am looking for a way to dynamically define classes and instantiate them in Android, at runtime. From my understanding, this is already done in Android, I just need some help figuring it out. I can a similiar result in Javascript and PHP. I know…
Jonathan
  • 5,495
  • 4
  • 38
  • 53
3
votes
2 answers

InaccessibleObjectException when trying to create CGLIB Spring proxy

Feb 02, 2022 12:58:03 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@71318ec4: startup date [Wed Feb 02 12:58:03 IST 2022]; root of…
3
votes
2 answers

In Spring, why are line numbers lost for CGLib on a POJO?

Spring MVC web app: I have a stack trace w/o line numbers (shown at bottom). I presume that this is due to CGLib running on the controller. But this is odd to me, the actual exception occurs in ServerBatchRemoteRequestAcceptor, a pojo that is not…
David Parks
  • 30,789
  • 47
  • 185
  • 328
3
votes
3 answers

Maven - Failed to resolve artifact - cglib:cglib-nodep:jar:null

I'm trying to build a large project and failing with the following error: [INFO] ------------------------------------------------------------------------ [INFO] Building Utilities [INFO] task-segment: [install] [INFO]…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
3
votes
1 answer

Mocking a class with @Transactional method with Mockito

I have a service, a bean, that contains a @Transactional method: public class InMessageService { ... @Transactional public boolean retryInMessage(String messageId) { ... } } For testing, I try to mock that service with…
Tchypp
  • 1,075
  • 2
  • 13
  • 20
3
votes
1 answer

Spring CGLib proxy - class variables become null

I have a filter service whose methods are profiled through the aspect. As an example I will give you a piece of code where I have a problem @Service public class FilterService extends AbstractService { private static final Logger log…
Peter Kozlovsky
  • 633
  • 2
  • 10
  • 28
3
votes
1 answer

Invoke an interface default method on a proxy

How do I create a proxy and invoke default interface methods as if they were implemented by the proxy super-class? For example: interface Foo { default int returnSomething() { return 1; } } interface Bar extends Foo { default…
Giovanni Lovato
  • 2,183
  • 2
  • 29
  • 53