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

  • SEARCH
  • Home
  • 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 9253743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:17:44+00:00 2026-06-18T11:17:44+00:00

I run out of ideas, Google also did not help. Use case seems to

  • 0

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 Category selectElement(List<? extends Category> results, Code code) {
    return selectFirst(results, having(on(Category.class).getCode(), is(code)));
}

Execution gives this top of the stack:

java.lang.ClassCastException: name.wilu.logic.report.utils.SheetLoader$Category$$EnhancerByCGLIB$$3a35aefc cannot be cast to net.sf.cglib.proxy.Factory
at ch.lambdaj.proxy.ClassImposterizer.createProxy(ClassImposterizer.java:134)
at ch.lambdaj.proxy.ClassImposterizer.imposterise(ClassImposterizer.java:101)
at ch.lambdaj.proxy.ProxyUtil.createProxy(ProxyUtil.java:52)
at ch.lambdaj.function.argument.ArgumentsFactory.createPlaceholder(ArgumentsFactory.java:68)
at ch.lambdaj.function.argument.ArgumentsFactory.registerNewArgument(ArgumentsFactory.java:58)
at ch.lambdaj.function.argument.ArgumentsFactory.createArgument(ArgumentsFactory.java:50)
at ch.lambdaj.function.argument.ArgumentsFactory.createArgument(ArgumentsFactory.java:39)
at ch.lambdaj.Lambda.on(Lambda.java:63)

I had the same problem while using lambdaJ for manipulation over hibernate’s persistent collections holding entities. I gave up assuming there might be some problem with proxying objects (entities in collection) that already are proxies.
It seems I were wrong because Category and all inherited classes are pojos passsed to the hibernate as a result transformer.

What might be a reason of such behavior?
Do you have any idea?

(I’m using the most recent lambdaj-2.4).

Added to fulfill Mario’s request

Code is a simple enum.
Category is a base class for different categories, it has code field. Moreover, it’s public static class, same as all inheriting classes (if it matters).

I’ll try to provide failing test.

Editing again to provide additional info.
A friend of mine took a look on the code and put a fresh bright light on the issue.

I will try to reproduce our path of deduction from the very beginning.

// Given

There’s an application divided into two parts, the first – base application (keeps model files) and the web application (keeps UI connected files like backing beans and so forth).
Our category and code are model classes thus are located in base application. We have then a backing bean serving for the purpose of some web logic and particularly that bean or its collaborator calls our select.

// When

We’re deploying application to a web server! JBoss in my case. Classes are read by loaders, some pretty complicated things that I’m not aware of happen, all to have my application running.
I do some web action and that backing bean’s method is called

 selectFirst(results, having(on(Category.class).getCode(), is(code)));

from web part of application.

Here comes the magic.
Our Category.class and Code.class were loaded by UnifiedClassLoader on application load.
We’re in on(Category.class) method and the proxy of Category is going to be built. Some really tangled logic is harnessed to do that, What’s the most important, proxy is instrumented with

setThreadsCallbacks(Callback[]callbacks) 

method, but Callback.class is taken from that class loader

 aCategory.getClass.getClassLoader()

thus it is a class loader that initially loaded that class, the UnifiedClassLoader .
Having all this done cleanly we finally call

 getFirstInstance()

that using reflection browses Proxy class seeking for:
Proxy.getDeclaredMethod(“setThreadsCallbacks”, new Class[]{ Callback[].class });

I omit the fact, I do not understand

 new Class[]{ Callback[].class }

What’s important in our case is that Callback.class is NOT PROVIDED BY UnifiedClassLoader.
Applicaiton is executed in a web tire so a call for Callback.class will be server by web app. class loader and retured Callback.class will dffer from what was previously put as an argment for mentioned setThreadsCallbacks functon. Reflection fails cruelly.

Category.class != Category.class //these two were provided by different classLoaders

That is why I was not able to provide failing test. (same class loader).

I doubt there’s any solution for that case.

  • 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-06-18T11:17:46+00:00Added an answer on June 18, 2026 at 11:17 am

    I have encountered a similar problem. (The same exception thrown: java.lang.ClassCastException: XXX$Category$$EnhancerByCGLIB$$XXX cannot be cast to net.sf.cglib.proxy.Factory)

    In my case it turned out to be a problem with duplicated (or even tripled) CGLib library. We had as follows:

    • cglib.jar in JBoss (4.2.3) library
    • cglib-nodep.jar in our application web-library (WAR file)
    • labmdaj-2.4-with-dependencies.jar in application web-library.

    Then, when using Lambda.on(SomeClass.class) we get to this method in CGLib’s Enhancer class:

    private static Method getCallbacksSetter(Class type, String methodName) throws NoSuchMethodException {
            return type.getDeclaredMethod(methodName, new Class[]{ Callback[].class });
    }
    

    where methodName = "CGLIB$SET_THREAD_CALLBACKS"
    and type is our SomeClass wrapped by Enhancer.

    “CGLIB$SET_THREAD_CALLBACKS” method was present in wrapped type, but getDeclaredMethod() returned null. It appeared that inside getDeclaredMethod() there was a comparison of two net.sf.cglib.proxy.Callback.class instances. And they were different since one was loaded from cglib.jar (JBoss) and the other from cglib-nodep.jar (webapp).

    The solution was to delete redundant cglib-nodep.jar and replace lambda-2.4-with-dependencies.jar with lambda-2.4.jar. Now all CGLib classes are loaded from common place and the problems have gone.

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

Sidebar

Related Questions

Do you ever run into a bug where you are just out of ideas
I am working on some homework here, but I have completely run out of
Our system uses a lot of large Bitmaps (System.Drawing.Bitmap) and sometimes we run out
When an exe file is run it prints out some stuff. I'm trying to
My html: <input id=Text2 type=text title=nepal name=text /> when I run this.My out put
I'm trying to run just one migration out of a whole bunch in my
I'm trying to run a script that will fade out all the divs selected
I'm trying to work out how to run a process in a background thread
I'm trying to figure out where java Applets that I run from the browser
I just want to find out how to run two WPF windows (one in

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.