ExceptionConverter.java

1
/*
2
 * The contents of this file are subject to the Mozilla Public License Version 1.1
3
 * (the "License"); you may not use this file except in compliance with the License.
4
 * You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
 *
6
 * Software distributed under the License is distributed on an "AS IS" basis,
7
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
 * for the specific language governing rights and limitations under the License.
9
 *
10
 * The Original Code is 'iText, a free JAVA-PDF library'.
11
 *
12
 * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
13
 * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
14
 * All Rights Reserved.
15
 * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
16
 * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
17
 *
18
 * Contributor(s): all the names of the contributors are added in the source code
19
 * where applicable.
20
 *
21
 * Alternatively, the contents of this file may be used under the terms of the
22
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
23
 * provisions of LGPL are applicable instead of those above.  If you wish to
24
 * allow use of your version of this file only under the terms of the LGPL
25
 * License and not to allow others to use your version of this file under
26
 * the MPL, indicate your decision by deleting the provisions above and
27
 * replace them with the notice and other provisions required by the LGPL.
28
 * If you do not delete the provisions above, a recipient may use your version
29
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
30
 *
31
 * This library is free software; you can redistribute it and/or modify it
32
 * under the terms of the MPL as stated above or under the terms of the GNU
33
 * Library General Public License as published by the Free Software Foundation;
34
 * either version 2 of the License, or any later version.
35
 *
36
 * This library is distributed in the hope that it will be useful, but WITHOUT
37
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
38
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
39
 * details.
40
 *
41
 * If you didn't download this code from the following link, you should check if
42
 * you aren't using an obsolete version:
43
 * http://www.lowagie.com/iText/
44
 */
45
46
/*
47
 * The original version of this class was published in an article by professor Heinz Kabutz.
48
 * Read http://www.javaspecialists.co.za/archive/newsletter.do?issue=033&print=yes&locale=en_US
49
 * "This material from The Java(tm) Specialists' Newsletter by Maximum Solutions (South Africa).
50
 * Please contact Maximum Solutions  for more information."
51
 *
52
 * Copyright (C) 2001 Dr. Heinz M. Kabutz
53
 */
54
55
/**
56
 * The OpenPDF project has permission from the author to use this class under a LGPL/MPL license on 2018-08-06:
57
 *
58
 * Hi Andreas,
59
 *
60
 * you have my permission to use my code with your license.
61
 *
62
 * Regards
63
 *
64
 *
65
 * Heinz
66
 * --
67
 * Dr Heinz M. Kabutz (PhD CompSci)
68
 */
69
70
package com.lowagie.text;
71
72
/**
73
 * The ExceptionConverter changes a checked exception into an
74
 * unchecked exception.
75
 */
76
public class ExceptionConverter extends RuntimeException {
77
    private static final long serialVersionUID = 8657630363395849399L;
78
    /** we keep a handle to the wrapped exception */
79
    private Exception ex;
80
    /** prefix for the exception */
81
    private String prefix;
82
83
    /**
84
     * Construct a RuntimeException based on another Exception
85
     * @param ex the exception that has to be turned into a RuntimeException
86
     */
87
    public ExceptionConverter(Exception ex) {
88
        this.ex = ex;
89 1 1. : negated conditional → NO_COVERAGE
        prefix = (ex instanceof RuntimeException) ? "" : "ExceptionConverter: ";
90
    }
91
92
    /**
93
     * Convert an Exception into an unchecked exception. Return the exception if it is
94
     * already an unchecked exception or return an ExceptionConverter wrapper otherwise
95
     *
96
     * @param ex the exception to convert
97
     * @return an unchecked exception 
98
     * @since 2.1.6
99
     */
100
    public static final RuntimeException convertException(Exception ex) {
101 1 1. convertException : negated conditional → NO_COVERAGE
        if (ex instanceof RuntimeException) {
102 1 1. convertException : mutated return of Object value for com/lowagie/text/ExceptionConverter::convertException to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
            return (RuntimeException) ex;
103
        }
104 1 1. convertException : mutated return of Object value for com/lowagie/text/ExceptionConverter::convertException to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return new ExceptionConverter(ex);
105
    }
106
107
    /**
108
     * and allow the user of ExceptionConverter to get a handle to it. 
109
     * @return the original exception
110
     */
111
    public Exception getException() {
112
        return ex;
113
    }
114
115
    /**
116
     * We print the message of the checked exception 
117
     * @return message of the original exception
118
     */
119
    public String getMessage() {
120
        return ex.getMessage();
121
    }
122
123
    /**
124
     * and make sure we also produce a localized version
125
     * @return localized version of the message
126
     */
127
    public String getLocalizedMessage() {
128
        return ex.getLocalizedMessage();
129
    }
130
131
    /**
132
     * The toString() is changed to be prefixed with ExceptionConverter 
133
     * @return String version of the exception
134
     */
135
    public String toString() {
136
        return prefix + ex;
137
    }
138
139
    /** we have to override this as well */
140
    public void printStackTrace() {
141 1 1. printStackTrace : removed call to com/lowagie/text/ExceptionConverter::printStackTrace → NO_COVERAGE
        printStackTrace(System.err);
142
    }
143
144
    /**
145
     * here we prefix, with s.print(), not s.println(), the stack
146
     * trace with "ExceptionConverter:" 
147
     * @param s
148
     */
149
    public void printStackTrace(java.io.PrintStream s) {
150
        synchronized (s) {
151 1 1. printStackTrace : removed call to java/io/PrintStream::print → NO_COVERAGE
            s.print(prefix);
152 1 1. printStackTrace : removed call to java/lang/Exception::printStackTrace → NO_COVERAGE
            ex.printStackTrace(s);
153
        }
154
    }
155
156
    /**
157
     * Again, we prefix the stack trace with "ExceptionConverter:" 
158
     * @param s
159
     */
160
    public void printStackTrace(java.io.PrintWriter s) {
161
        synchronized (s) {
162 1 1. printStackTrace : removed call to java/io/PrintWriter::print → NO_COVERAGE
            s.print(prefix);
163 1 1. printStackTrace : removed call to java/lang/Exception::printStackTrace → NO_COVERAGE
            ex.printStackTrace(s);
164
        }
165
    }
166
167
    /**
168
     * requests to fill in the stack trace we will have to ignore.
169
     * We can't throw an exception here, because this method
170
     * is called by the constructor of Throwable 
171
     * @return a Throwable
172
     */
173
    public Throwable fillInStackTrace() {
174 1 1. fillInStackTrace : mutated return of Object value for com/lowagie/text/ExceptionConverter::fillInStackTrace to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
        return this;
175
    }
176
}

Mutations

89

1.1
Location :
Killed by : none
negated conditional → NO_COVERAGE

101

1.1
Location : convertException
Killed by : none
negated conditional → NO_COVERAGE

102

1.1
Location : convertException
Killed by : none
mutated return of Object value for com/lowagie/text/ExceptionConverter::convertException to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

104

1.1
Location : convertException
Killed by : none
mutated return of Object value for com/lowagie/text/ExceptionConverter::convertException to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

141

1.1
Location : printStackTrace
Killed by : none
removed call to com/lowagie/text/ExceptionConverter::printStackTrace → NO_COVERAGE

151

1.1
Location : printStackTrace
Killed by : none
removed call to java/io/PrintStream::print → NO_COVERAGE

152

1.1
Location : printStackTrace
Killed by : none
removed call to java/lang/Exception::printStackTrace → NO_COVERAGE

162

1.1
Location : printStackTrace
Killed by : none
removed call to java/io/PrintWriter::print → NO_COVERAGE

163

1.1
Location : printStackTrace
Killed by : none
removed call to java/lang/Exception::printStackTrace → NO_COVERAGE

174

1.1
Location : fillInStackTrace
Killed by : none
mutated return of Object value for com/lowagie/text/ExceptionConverter::fillInStackTrace to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2