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 6145577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:48:50+00:00 2026-05-23T18:48:50+00:00

Steps i perform to create dynamic class is as follows: try { classLoader =

  • 0

Steps i perform to create dynamic class is as follows:

      try
      {

            classLoader = Class.forName("org.yaddayadda.DynamicClass" + genericType.getName().toLowerCase() + uniqueID);
        }
        catch (ClassNotFoundException classNotFoundException)
        {
        }

        if (classLoader == null)
        {
            dynamicClass = pool.get("org.yaddayadda.DynamicClass");
            dynamicClass.defrost();
            dynamicClass.replaceClassName("org.yaddayadda.DynamicClass","org.yaddayadda.DynamicClass"+ genericType.getName().toLowerCase() + uniqueID);

            dynamicClass.defrost();


            CtMethod readObject = dynamicClass.getDeclaredMethod("Method1");
            CtMethod writeObject = dynamicClass.getDeclaredMethod("Method2");

            StringBuffer method1= new StringBuffer();
            StringBuffer method2= new StringBuffer();

            GenerateDynamicCode.generateCode(genericType, method1, method2);

            writeObject.insertAt(1, method1.toString());
            readObject.insertAt(1, method2.toString());

            //This is where the exception is thrown
            classLoader = dynamicClass.toClass();
        }

I first try to check if the class already exists in ClassPool if not then i proceed on to creating a class. Defrost is done for just a fail-safe mechanism. The Exception comes when the method toClass is called dynamicClass.toClass();

The Exception is as follows

    Exception Message: null
    Stack Trace: 
    sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    javassist.ClassPool.toClass2(ClassPool.java:1102)
    javassist.ClassPool.toClass(ClassPool.java:1083)
    javassist.ClassPool.toClass(ClassPool.java:1032)
    javassist.ClassPool.toClass(ClassPool.java:990)
    javassist.CtClass.toClass(CtClass.java:1125)
    This Class

What is the reason of the above exception and what can be done to avoid 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-23T18:48:51+00:00Added an answer on May 23, 2026 at 6:48 pm

    Well i have found a solution, in fact a workaround i.e. i simply call in a loop again defrosting the compiled class and redoing everything i just tried when an exception comes and the loop runs at most 3 times just to be on the safe side

            int i = 0;
            while (classLoader == null)
            {
                try
                {
                    if (classLoader == null)
                    {
                        dynamicClass = pool.get("org.yaddayadda.DynamicClass");
                        dynamicClass.defrost();
    
    
                        try
                        {
                            dynamicSurrugate = pool.get("org.yaddayadda.DynamicClass" + genericType.getName().toLowerCase() + uniqueID);
    
                            dynamicSurrugate.defrost();
                        }
                        catch (NotFoundException notFoundException)
                        {
                        }
    
    
                        //Everything the same
                    }
                }
                catch (Exception exception)
                {
                    classLoader = null;
                    i++;
                }
    
                if (i == 3)
                {
                    throw new Exception("IF failed throw message third time");
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have perform two steps a) Create a some random xml file in
What steps I need to perform in order to convert asp.net 2 application from
Here are my steps: switch from trunk to my branch perform a merge from
Rep steps: create example .NET form application put a TextBox on the form wire
I'm working on a new application to perform certain steps on certain order defined
If you had to create a list of steps that a non-technical business layperson
Steps: Run the build including unit tests. Expected result: the unit tests are executed
What steps do I take? Any gotchas to be aware of or tips to
What steps do I have to take to configure my sendmail server to implement
First steps in FreeBSD: trying to run my installation script. Fast help needed: #

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.