added -J option to preserve unmodified files in preexisting jarfile
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / classfmt / ClassFormatException.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others. All rights reserved.
3  * This program and the accompanying materials are made available under the
4  * terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  * 
7  * Contributors: IBM Corporation - initial API and implementation
8  ******************************************************************************/
9 package org.eclipse.jdt.internal.compiler.classfmt;
10 import java.io.PrintStream;
11 import java.io.PrintWriter;
12 public class ClassFormatException extends Exception {
13         
14         public static final int ErrBadMagic = 1;
15         public static final int ErrBadMinorVersion = 2;
16         public static final int ErrBadMajorVersion = 3;
17         public static final int ErrBadConstantClass = 4;
18         public static final int ErrBadConstantString = 5;
19         public static final int ErrBadConstantNameAndType = 6;
20         public static final int ErrBadConstantFieldRef = 7;
21         public static final int ErrBadConstantMethodRef = 8;
22         public static final int ErrBadConstantInterfaceMethodRef = 9;
23         public static final int ErrBadConstantPoolIndex = 10;
24         public static final int ErrBadSuperclassName = 11;
25         public static final int ErrInterfaceCannotBeFinal = 12;
26         public static final int ErrInterfaceMustBeAbstract = 13;
27         public static final int ErrBadModifiers = 14;
28         public static final int ErrClassCannotBeAbstractFinal = 15;
29         public static final int ErrBadClassname = 16;
30         public static final int ErrBadFieldInfo = 17;
31         public static final int ErrBadMethodInfo = 17;
32         public static final int ErrEmptyConstantPool = 18;
33         public static final int ErrMalformedUtf8 = 19;
34         public static final int ErrUnknownConstantTag = 20;
35         public static final int ErrTruncatedInput = 21;
36         public static final int ErrMethodMustBeAbstract = 22;
37         public static final int ErrMalformedAttribute = 23;
38         public static final int ErrBadInterface = 24;
39         public static final int ErrInterfaceMustSubclassObject = 25;
40         public static final int ErrIncorrectInterfaceMethods = 26;
41         public static final int ErrInvalidMethodName = 27;
42         public static final int ErrInvalidMethodSignature = 28;
43
44         private static final long serialVersionUID = 6667458511042774540L; // backward compatible
45
46         private int errorCode;
47         private int bufferPosition;
48         private RuntimeException nestedException;
49         private char[] fileName;
50
51         public ClassFormatException(RuntimeException e, char[] fileName) {
52                 this.nestedException = e;
53         }
54         public ClassFormatException(int code) {
55                 errorCode = code;
56         }
57         public ClassFormatException(int code, int bufPos) {
58                 errorCode = code;
59                 bufferPosition = bufPos;
60         }
61         /**
62          * @return int
63          */
64         public int getErrorCode() {
65                 return errorCode;
66         }
67         /**
68          * @return int
69          */
70         public int getBufferPosition() {
71                 return bufferPosition;
72         }
73         /**
74          * Returns the underlying <code>Throwable</code> that caused the failure.
75          * 
76          * @return the wrappered <code>Throwable</code>, or <code>null</code>
77          *         if the direct case of the failure was at the Java model layer
78          */
79         public Throwable getException() {
80                 return this.nestedException;
81         }
82         public void printStackTrace() {
83                 printStackTrace(System.err);
84         }
85         /**
86          * Prints this exception's stack trace to the given print stream.
87          * 
88          * @param output
89          *            the print stream
90          * @since 3.0
91          */
92         public void printStackTrace(PrintStream output) {
93                 synchronized (output) {
94                         super.printStackTrace(output);
95                         Throwable throwable = getException();
96                         if (throwable != null) {
97                                 if (this.fileName != null) {
98                                         output.print("Caused in "); //$NON-NLS-1$
99                                         output.print(this.fileName);
100                                         output.print(" by: "); //$NON-NLS-1$
101                                 } else {
102                                         output.print("Caused by: "); //$NON-NLS-1$
103                                 }
104                                 throwable.printStackTrace(output);
105                         }
106                 }
107         }
108         /**
109          * Prints this exception's stack trace to the given print writer.
110          * 
111          * @param output
112          *            the print writer
113          * @since 3.0
114          */
115         public void printStackTrace(PrintWriter output) {
116                 synchronized (output) {
117                         super.printStackTrace(output);
118                         Throwable throwable = getException();
119                         if (throwable != null) {
120                                 if (this.fileName != null) {
121                                         output.print("Caused in "); //$NON-NLS-1$
122                                         output.print(this.fileName);
123                                         output.print(" by: "); //$NON-NLS-1$
124                                 } else {
125                                         output.print("Caused by: "); //$NON-NLS-1$
126                                 }
127                                 throwable.printStackTrace(output);
128                         }
129                 }
130         }
131 }