How to work around broken third party Exception class

Discussion in 'Java' started by Brian J. Sayatovic, Sep 5, 2003.

  1. I'm using a third-party library whose API throws various Exceptions
    that all extend one of their base exception classes. However, in some
    cases, their library is throwing instances of their Exceptions which
    throw a NullPointerException when calling .getMessage() (remember,
    getMessage() is also called implicitly by toString() and
    printStackTrace())...

    try {
    // ...
    }
    catch(ThirdPartyException tpe) {
    // *** Throws a NullPointerException!
    System.out.println(tpe.getMessage());
    }

    I've found out this is because their Exceptions use a "details" object
    to carry the message, so I'm assuming their getMessage() method
    accesses this details object to get the message to return. However,
    in some cases, they do NOT initialize this details object for the
    Exception (I actually read their docs where it says they will
    initialize it to a default instance, but in practice they don't --
    I've tested). However, they do expose a method to check the details,
    getDetails().

    So, how can I print out the stack trace of these exceptions so I can
    at least find their source without the accompanying description? I
    already tried using reflection to check the private field they store
    the information in, make it accessible and then set the instance if it
    is null; however, I ran into security problems and can't realisticly
    change the policy for production. I thought about making a wrapping
    delegate, but I couldn't quite figure out how it would work.

    This is a pseudo-API of their Exception base class, if it helps:

    public class ThirdPartyException extends Exception {

    // Leaves the details member set to null
    public ThirdPartyException();

    // Sets the third-party details appropriately
    public ThirdPartyException(ThirdPartyDetails details);

    // Returns the message from the third-party details
    public String getMessage();

    // Returns the member
    public ThirdPartyDetails getDetails();

    }

    public class ThirdPartyDetails() {
    // Returns the actual message descripting the exception
    public String getMessage();
    }

    Regards,
    Brian.
     
    Brian J. Sayatovic, Sep 5, 2003
    #1
    1. Advertising

  2. (Brian J. Sayatovic) writes:
    > So, how can I print out the stack trace of these exceptions so I can
    > at least find their source without the accompanying description?


    Without knowing much details, here is what I would try:

    1) Call them and ask for a bug fix.

    2) Call them, yell at them and ask for a bug fix

    3) Call them, yell at them and ask for my money back

    If this doesn't help, I would consider decompiling the library, fix the
    constructor, and re-package the library. You should, however, check the
    license and laws first.

    YMMV

    /Thomas
     
    Thomas Weidenfeller, Sep 5, 2003
    #2
    1. Advertising

  3. Brian J. Sayatovic

    rkm Guest

    Brian J. Sayatovic wrote:
    > So, how can I print out the stack trace of these exceptions so I can
    > at least find their source without the accompanying description?


    Create your own ThirdPartyException class and replace theirs
    with yours?
     
    rkm, Sep 5, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kieran Benton
    Replies:
    3
    Views:
    524
    Ray Cassick \(home\)
    Sep 11, 2003
  2. Billy Porter
    Replies:
    0
    Views:
    1,039
    Billy Porter
    Jun 25, 2003
  3. Mikael Engdahl

    Strange error when calling third party assembly

    Mikael Engdahl, Aug 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    371
    Mikael Engdahl
    Aug 8, 2003
  4. ASPQuicky
    Replies:
    1
    Views:
    107
    Ken Cox [Microsoft MVP]
    Oct 13, 2004
  5. Donald Canton

    Third party cookies...how do they work?

    Donald Canton, Aug 23, 2003, in forum: Javascript
    Replies:
    2
    Views:
    169
    Randell D.
    Sep 5, 2003
Loading...

Share This Page