Giter Site home page Giter Site logo

Comments (8)

tracts-root avatar tracts-root commented on July 28, 2024

Figured I would just confirm: simply omitting the throwable argument from the super call works fine. So that would read

public JSONRPCException(final CODE code, final String description, final Throwable t) {
    super(description);
    init(code, description, t);
}

from eve.

ludost avatar ludost commented on July 28, 2024

Hi Erik,

Which release/version are you referring to? In the Master I've done a fix that probably fixes your mentioned issue, but it had not been ported back to 2.2.1 as it was contained in a larger unrelated commit. I'll patch 2.2.1 now, can you check if that helps?

from eve.

tracts-root avatar tracts-root commented on July 28, 2024

Hi Ludo,

Thanks! I think the extra clause you added to init(), namely to check that getCause() == null before attempting to call initCause should work fine in most cases. However if we called the JSONRPCException constructor with the Throwable argument set to null (which according to the java docs is actually a reasonable thing to do) then it will still go wrong.

This latter cornercase might be a minor advantage of my suggested fix -- simply not passing the t argument to the super constructor -- compared to this extra test inside init.

from eve.

tracts-root avatar tracts-root commented on July 28, 2024

@ludost Sorry didn't mean to close it just yet, at least until you read my comment :-)

from eve.

tracts-root avatar tracts-root commented on July 28, 2024

@ludost Looking at the source for Throwable it looks like the test getCause()==null will not work... http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7u40-b43/java/lang/Throwable.java#Throwable
The cause field is initialized to this, not null, so I expect your test will not do what it should when one of the constructors without a throwable is used.

So I guess the way to get this working properly for all constructor variants is not to pass any throwable to the super constructor and remove the getCause() test from init?

from eve.

ludost avatar ludost commented on July 28, 2024

The problem is that super(t) is different than setCause(t). And I like to have the behaviour of super(t) :)

But back to your statement, which is incorrect: the getCause()==null will work:

public synchronized Throwable getCause() {
     return (cause==this ? null : cause);
}

So, please test my latest commit in your code, I believe it will fix the issue.

PS: I fail to see why putting a null-cause would lead to a problem? Throwable seems to handle that case correctly in its constructors and hopefully JSONRPCException as well.

from eve.

tracts-root avatar tracts-root commented on July 28, 2024

Ah, I had not noticed this quirk in getCause. I did test it, actually, and my immediate problem is resolved. I still wonder about calling a constructor with t==null but as far as I know we're not doing that.

Thanks!

Oh and just curious, what is the difference between super(t) and setCause(t) that you mentioned?

from eve.

ludost avatar ludost commented on July 28, 2024

An indication about the safety of the constructors is this statement from one of these constructors:

 detailMessage = (cause==null ? null : cause.toString());

Which explicitly checks for null causes.

from eve.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.