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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:20:30+00:00 2026-06-08T21:20:30+00:00

I have a constructor that fails on the first call to new because an

  • 0

I have a constructor that fails on the first call to new because an Exception of class javax.persistence.NoResultException being catch in one of the Class’ methods.

EDIT: It was not a NoResultException, the NoResultException was the message of the Exception. The stackTrace is below

If I remove the import to javax.persistence.NoResultException and catch just a generic Exception e, the code works.

My questions are:

  1. Why is the code inside a method which hasn’t been called is affecting the Constructor? (is not being called in the constructor either)
  2. Why is the ClassLoader throwing an exception which is not supposed to throw? ClassLoader.loadClass() throws ClassNotFoundException according to JavaDoc.

that catch for javax.persistence.NoResultException as well as the import are old code which managed to survive between versions, I removed it and it’s fixed, however I’d like to now the reason behind this.

STACKTRACE:

java.lang.NoClassDefFoundError: javax/persistence/NoResultException
    at xxx.xxxxxx.xxxxxxx.xxxx.xxxx.xxxxxxxxxxxx.xxxxxxxxxxxxxxx(ClassB.java)
    ...
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: javax.persistence.NoResultException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    ... 10 more

Go to the end to see the step by step images of the debugger and the moment it fails

FAILING CODE:

// ClassB.java

import javax.persistence.NoResultException; // NOTICE THE IMPORT

public ClassB{
    private UserInfo user;
    private WebServiceBDelegate port;
    private Connection conn;

    public ClassB (UserInfo user, Connection conn) throws Exception {
        System.out.println("CLASS B CONSTRUCTOR");
        this.user = user;
        this.conn = conn;
        this.port = new WebServiceBService().getForwardingPort();
    }

    public boolean methodB(List<String> list){
        try{
            // Check some stuff on database using this.conn
        } catch(NoResultException nre){         // NOTICE THE CATCH
            String something = getSomething();
        }
        // Get the values to invoke SOAP service using this.conn
        status = port.operationB(values);
        if(status > 0)
            return true;
        return false;
    }
}

WORKING CODE:

// ClassB.java

public ClassB{
    private UserInfo user;
    private WebServiceBDelegate port;
    private Connection conn;

    public ClassB (UserInfo user, Connection conn) throws Exception {
        System.out.println("CLASS B CONSTRUCTOR");
        this.user = user;
        this.conn = conn;
        this.port = new WebServiceBService().getForwardingPort();
    }

    public boolean methodB(List<String> list){
        try{
            // Check some stuff on database using this.conn
        } catch(Exception e){         // THIS IS THE CHANGED CATCH
            String something = getSomething();
        }
        // Get the values to invoke SOAP service using this.conn
        status = port.operationB(values);
        if(status > 0)
            return true;
        return false;
    }
}

Here are the step by step images from the debugger when entering INTO the class constructor, to the JVM default ClassLoader and the moment it fails:

STEP INTO when calling new ClassB gets me to loadClassInternal(String)
STEP INTO when calling new ClassB gets me to loadClassInternal(String)

STEP INTO loadClassInternal(String), gets me to loadClass(String,boolean)
STEP INTO loadClassInternal(String), gets me to loadClass(String,boolean)

STEP INTO loadClass(String,boolean), as far as I can get, now STEP RETURN
STEP INTO loadClass(String,boolean), as far as I can get, now STEP RETURN

STEP RETURN gets me to loadClass(String)
STEP RETURN gets me to loadClass(String)

STEP OVER gets me to loadClassInternal(String)
STEP OVER gets me to loadClassInternal(String)

STEP OVER gives me javax.persistence.NoResultException
STEP OVER gives me javax.persistence.NoResultException

STEP OVER TAKES ME BACK TO A FINALLY IN MY CODE AND ENDS EXECUTION

  • 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-08T21:20:32+00:00Added an answer on June 8, 2026 at 9:20 pm
    1. The class is loaded into the ClassLoader on first access. The first ‘new’ statement in your code loads the class into the ClassLoader, which subsequently checks whether it actually has access to all the dependencies of your class (ie. the NoResultException).
    2. You’re not making it clear what is being thrown by the ClassLoader, but my guess is it does throw a ClassNotFoundException detailing that the NoResultException is not on your classpath, so it cannot be loaded. That’s also why it works when you remove the offending import and catch.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on someone's code and they have a constructor that uses: class qwerty
I have a class constructor that expects a reference to another class object to
So I have a base class with a constructor that takes (T V) .
I have a constructor (for an auto generated class) that has 255 paremeters. Using
I want to throw an exception in my constructor so that I don't have
I have a constructor that has a series of classes and functions within it
I have a constructor that looks like this (in c++): Interpreter::Interpreter() { tempDat ==
I know that you can't have a constructor in an interface, but here is
I have a constructor for a window in my project setup such that it
I want to have a constructor with an argument that gets inherited by all

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.