Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6251103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:33:03+00:00 2026-05-24T13:33:03+00:00

I use cglib MethodInterceptor to wrap a service. In each call to the service

  • 0

I use cglib MethodInterceptor to wrap a service. In each call to the service it’s supposed to open data session, pass call to the service and finally close the session.

However, I noticed it misbehaves when invoked from Finalizer. I get the following stacktrace:

java.lang.IllegalArgumentException: interface my.pkg.SomeInterface is not visible from class loader
        at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
        at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
        at my.pkg.ProxyFactory.create(ProxyFactory.java:68)
        at my.pkg.SomeService.make(SomeService.java:181)
        at my.pkg.SomeService$SessionWrappingInterceptor.intercept(SomeService.java:1275)
        at my.pkg.SomeService$$EnhancerByCGLIB$$b58faf6a.finalize(<generated>)
        at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
        at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
        at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)

What am I doing wrong? How can I resolve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:33:04+00:00Added an answer on May 24, 2026 at 1:33 pm

    When the finalizer finally picks your object (or your CGLIB proxy object) to finalize, the garbage collector has determined that your object is unreachable and is about to be discarded/collected. Let’s assume that this is not the only object being collected, and in fact other objects that it might have used in the past (including their classloaders) have since also been collected.

    There’s not enough information in your question to be certain about what is going on, but the general guess I have is that the work your ProxyFactory is doing requires classes that USED to be accessible to this classloader but no longer are, possibly due to the fact that you are in the last stages of garbage collection.

    I’ve learned the hard way that proxies that handle finalize() calls are downright dangerous. In most cases your proxy target really doesn’t need to handle that call, but if it does, don’t do anything in your proxy handler that is going to create, initialize or otherwise create references to the proxy target. (For instance, my case was a load-on-demand object. When finalize() was called, if the object had not been previously loaded, it would load it and cache the value somewhere that created a new strong reference chain, thereby disallowing the proxy class, its classloader, and many other classes it referenced to be collected. Massive memory leak.)

    My advice (late tho it is) is to disallow your proxy from handling finalize(). CGLIB’s Enhancer can be given CallbackFilters to indicate not to do anything with the finalize() method, or if you’re using the simple MethodInterceptor, you can check for that yourself.

    One last comment: careful with the CallbackFilters. They can also cause you memory leaks especially if they are coming from a different classloader than CGLIB is coming from! You’re going to end up with CGLIB-generated objects that hold on to your CallbackFilter instances that will not be garbage collected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use strict; use warnings; open(FILE1, /cygdrive/c/cpros/mola.txt); my $line = <FILE1>; print $line; close(FILE1); open(FILE1,
use Service layer to persist data into database. But the Unit Test does not
We use a data acquisition card to take readings from a device that increases
I'm noticing terrible speeds when trying to use CGLIB with a callback filter (on
use strict; use warnings; open(FILE1,/cygdrive/c/cpros/karthik/molk.txt); my $line = < FILE1 > ; print $line
I'm getting a strange error on a colleague's box. CGLib is auto-proxying a service
Is it still possible to force Hibernate 3.3 or 3.5 to use CGLib instead
Spring: 2.5.6.SEC01 DWR: 2.0.5 I would like to use a session scoped bean from
use case is simple: I want to run some boiler plate code before each
use a reapeter to display data, but sometimes the data is to big to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.