Java Code Examples for javax.xml.xpath.XPathException#initCause()

The following examples show how to use javax.xml.xpath.XPathException#initCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XPathExceptionInitCause.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 2
Source File: XPathExceptionInitCause.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 3
Source File: XPathExceptionInitCause.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 4
Source File: XPathExceptionInitCause.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 5
Source File: XPathExceptionInitCause.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 6
Source File: XPathExceptionInitCause.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 7
Source File: XPathExceptionInitCause.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 8
Source File: XPathExceptionInitCause.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 9
Source File: XPathExceptionInitCause.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 10
Source File: XPathExceptionInitCause.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 11
Source File: XPathExceptionInitCause.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 12
Source File: XPathExceptionInitCause.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}
 
Example 13
Source File: XPathExceptionInitCause.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Throwable cause = new Throwable("message 1");
    XPathException xpathexcep = new XPathException("message 2");

    //Test XPE initCause() method
    xpathexcep.initCause(cause);
    System.out.println("getCause() result: '" + xpathexcep.getCause()
            + "' Cause itself: '" + cause + "'");
    if (!xpathexcep.getCause().toString().equals(cause.toString())) {
        throw new Exception("Incorrect cause is set by initCause()");
    }

    //Test serialization/deserialization of initialized XPE
    byte [] xpeserial;
    XPathException xpedeser;
    xpeserial = pickleXPE(xpathexcep);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpathexcep.getMessage()
            + "' cause='" + xpathexcep.getCause().toString() + "'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause().toString()+"'");
    if(xpedeser.getCause() == null ||
            !xpedeser.getCause().toString().equals(cause.toString()) ||
            !xpedeser.getMessage().toString().equals("message 2") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test serialization/deserialization of uninitialized cause in XPE
    XPathException xpeuninit = new XPathException("uninitialized cause");
    xpeserial = pickleXPE(xpeuninit);
    xpedeser = unpickleXPE(xpeserial);
    System.out.println("Serialized XPE: message='" + xpeuninit.getMessage()
            + "' cause='" + xpeuninit.getCause()+"'");
    System.out.println("Deserialized XPE: message='" + xpedeser.getMessage()
            + "' cause='" + xpedeser.getCause()+"'");
    if(xpedeser.getCause() != null ||
            !xpedeser.getMessage().toString().equals("uninitialized cause") )
        throw new Exception("XPathException incorrectly serialized/deserialized");

    //Test deserialization of normal XPathException serialized by JDK7
    XPathException xpejdk7 = unpickleXPE(NORMALJDK7SER);
    if(xpejdk7 == null || xpejdk7.getCause() == null ||
            !xpejdk7.getMessage().equals("message 2") ||
            !xpejdk7.getCause().getMessage().equals("message 1"))
        throw new Exception("XpathException serialized by JDK7 was "
                + "incorrectly deserialized.");

    //Test deserialization of XPathException with two causes from JDK7.
    //The serialization are done for the following XPathException object:
    // new XPathException(new Exception()).initCause(null)
    try {
        xpejdk7 = unpickleXPE(TWOCAUSES);
        throw new Exception("Expected InvalidClassException but it wasn't"
                + " observed");
    } catch(InvalidClassException e) {
        System.out.println("InvalidClassException caught as expected.");
    }

}