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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:24:56+00:00 2026-05-23T02:24:56+00:00

When you use RMI in Java the remote stack trace of an exception will

  • 0

When you use RMI in Java the remote stack trace of an exception will be prepended when you receive it, somewhat like this:

ERROR Client received error when doing stuff:
myapp.FooBarException: bla
 at server.myMethod()
 at rmi.callHandler() // and now, on the next line comes the client
 at rmi.sendCall();
 at client.doServerMethod()
 at Thread.run()

How is that kind of stacktrace “forgery” done?


What do I want it for (apart from just being iterested)? Well, it would help me if I could do this:

outer() {

  thread = new Thread(...
      inner();
      // inner() throws
      // RuntimeException
      //  at inner();
      //  at Runnable.run();
      //  at Thread.run();
      //  at outer();
      //  at lalalala();
      //  ...

  ).start();

  thread.join();

}

And make it so that an exception thrown in inner() would have outer() (and methods lower down the chain) in the stacktrace as well, for logging purposes.

  • 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-23T02:24:57+00:00Added an answer on May 23, 2026 at 2:24 am

    It is kind of easy:

    Throwable has methods getStackTrace() and setStackTrace().

    From one of my projects (non open-source, but maybe I’ll some day open the remote call engine):

        /**
         * Setzt den Stack-Trace zusammen. Das untere Ende (tiefer in der
         * Aufrufhierarchie, am Anfang des Arrays/der Ausgabe) ist das,
         * welches im Throwable schon drin ist, das obere Ende wird aus
         * dem aktuellen Stack genommen. Dazwischen
         * kommt ein "Remote-Aufruf-Markierer".
         */
    

    Translated for your convenience:

    Merges the stack trace. The lower end (deeper in the call hierarchy, at the
    end of the array/the output) is what already is in the stack, the upper end
    will be taken from the current stack. Between them we will put an
    Remote call marker.

        private void mergeStackTraces(Throwable error)
        {
            StackTraceElement[] currentStack =
                new Throwable().getStackTrace();
            int currentStackLimit = 5; // TODO: raussuchen
            StackTraceElement[] oldStack =
                error.getStackTrace();
            StackTraceElement[] zusammen =
                new StackTraceElement[currentStack.length - currentStackLimit +
                                      oldStack.length + 1];
            System.arraycopy(oldStack, 0, zusammen, 0, oldStack.length);
            zusammen[oldStack.length] =
                new StackTraceElement("══════════════════════════",
                                      "<remote call %" +callID+ ">",
                                      "", -3);
            System.arraycopy(currentStack, currentStackLimit,
                             zusammen, oldStack.length+1,
                             currentStack.length - currentStackLimit);
            error.setStackTrace(zusammen);
        }
    

    (On the server side, I’m already cutting off the parts of the stack trace which do not relate to the method call itself, i.e. everything related to the message handling.)

    This results in a combined stack trace like this:

    java.lang.SecurityException: Das Passwort für Nutzer »Paul« ist falsch.
            at de.fencing_game.db.userdb.Db4oUserDB.login(Db4oUserDB.java:304)
            at de.fencing_game.server.impl.StandardServers$SSServer$1.run(StandardServers.java:316)
            at de.fencing_game.server.impl.StandardServers$SSServer$1.run(StandardServers.java:314)
            at java.security.AccessController.doPrivileged(Native Method)
            at de.fencing_game.server.impl.StandardServers$SSServer.login(StandardServers.java:313)
            at de.fencing_game.transport.server.ServerTransport$ConnectionInfo$4.login(ServerTransport.java:460)
            at ══════════════════════════.<remote call %2>()
            at $Proxy1.login(Unknown Source)
            at de.fencing_game.gui.basics.LoginUtils.login(LoginUtils.java:80)
            at de.fencing_game.gui.Lobby.connectTo(Lobby.java:302)
            at de.fencing_game.gui.Lobby$20.run(Lobby.java:849)
            at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:226)
            at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:647)
            at java.awt.EventQueue.access$000(EventQueue.java:96)
            at java.awt.EventQueue$1.run(EventQueue.java:608)
            at java.awt.EventQueue$1.run(EventQueue.java:606)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:105)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:617)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
    

    I suppose the RMI system does something quite similar (just without the ══════════════════════════).


    Edit:
    For your usecase, you would have to save the stack trace of the outer thread when the inner thread is started, then in the run method catch the exception and append the outer stack trace to the stack trace of the inner exception. I would really recommend putting some type of separator, though.

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

Sidebar

Related Questions

I very much like the simplicity of calling remote methods via Java's RMI, but
I am currently undertaking a project that involves extensive use of Java RMI and
I am just starting Java RMI and have some problems with when to use
How can I use RMI with a applet client behind a firewall? How can
I tried to run example from HornetQ and I got this error: [java] HornetQServer_0
I have to create a RMI program,when i run this program it will run
It's the first time I use java Rmi*. I have a custom class which
What are the possible names of remote objects in a java rmi registry? Are
I'm working on a project using Java RMI. This is the class causing problem:
Java RMI -Remote Method Invocation- is Java to Java only. On the Scala website

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.