Project Report: fawkez

Packagesummary org.jcoderz.commons.logging

org.jcoderz.commons.logging.StackTraceInfo

LineHitsNoteSource
1  /*
2   * $Id: StackTraceInfo.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.logging;
34  
35  import java.nio.CharBuffer;
36  
37  /**
38   * This helper class wraps the information of one stack trace line.
39   *
40   */
41 (1)public class StackTraceInfo
42  {
43     private static final String CURRENT_LINE_ERROR_TEXT
44           = "The current line is not a ";
45  
46     private final CharBuffer mStackTraceLine;
47  
48     /** Flag whether an 'at ...' line. */
49     private final boolean mIsLocationLine;
50     /** Flag whether an 'Caused by: ' line. */
51     private final boolean mIsCauseLine;
52     /** Flag whether an exception message line. */
53     private final boolean mIsExceptionMessageLine;
54     /** Flag whether an '... nnn more ' line. */
55     private final boolean mIsMoreLine;
56  
57     private final CharBuffer mClassName;
58     private final CharBuffer mMethodName;
59     private final int mLine;
60     private final int mMoreLines;
61  
62     private final CharBuffer mExceptionText;
63  
64     /**
65      * Constructs this and sets the information of an 'at ...' stack trace line.
66      *
67      * @param lineData Contains the original line data.
68      * @param className The parsed class name.
69      * @param methodName The parsed method name.
70      * @param line The parsed line number, is <= 0 if not available.
71      */
72     StackTraceInfo (
73           final CharBuffer lineData,
74           final CharBuffer className,
75           final CharBuffer methodName,
76           final int line)
770    {
780       mStackTraceLine = lineData;
79  
800       mIsLocationLine = true;
810       mIsCauseLine = false;
820       mIsExceptionMessageLine = false;
830       mIsMoreLine = false;
840       mClassName = className;
850       mMethodName = methodName;
860       mLine = line;
870       mMoreLines = -1;
880       mExceptionText = null;
890    }
90  
91     /**
92      * Constructs this and sets the information of an '... nnn more' stack trace
93      * line.
94      *
95      * @param lineData Contains the original line data.
96      * @param lines The parsed number of lines being omitted.
97      */
98     StackTraceInfo (
99           final CharBuffer lineData,
100           final int lines)
1010    {
1020       mStackTraceLine = lineData;
103  
1040       mIsLocationLine = false;
1050       mIsCauseLine = false;
1060       mIsExceptionMessageLine = false;
1070       mIsMoreLine = true;
1080       mClassName = null;
1090       mMethodName = null;
1100       mLine = -1;
1110       mMoreLines = lines;
1120       mExceptionText = null;
1130    }
114  
115     /**
116      * Constructs this and sets the information of an stack trace line, which
117      * contains the exception message.
118      *
119      * @param lineData Contains the original line data.
120      * @param message The exception message as it is parsed from
121      * <code>lineData</code>.
122      * @param isCause Flag whether the exception is a cause, i.e. whether the
123      * message ahs a 'Caused by: ' prefix.
124      */
125     StackTraceInfo (
126           final CharBuffer lineData,
127           final CharBuffer message,
128           final boolean isCause)
1290    {
1300       mStackTraceLine = lineData;
131  
1320       mIsLocationLine = false;
1330       mIsCauseLine = isCause;
1340(2)      mIsExceptionMessageLine = ! isCause;
1350       mIsMoreLine = false;
1360       mClassName = null;
1370       mMethodName = null;
1380       mLine = -1;
1390       mMoreLines = -1;
1400       mExceptionText = message;
1410    }
142  
143     /**
144      * Returns the wrapped stack trace line as string.
145      *
146      * @return The stack trace line.
147      *
148      * @see java.lang.Object#toString()
149      */
150     public String toString ()
151     {
1520       return String.valueOf(mStackTraceLine);
153     }
154  
155     /**
156      * Gets flag whether the current line is a caused-by line.
157      *
158      * @return true if the current line is a caused-by line; false, else.
159      */
160     boolean isCauseLine ()
161     {
1620       return mIsCauseLine;
163     }
164  
165     /**
166      * Gets flag whether the current line contained the exception message with or
167      * without the 'Caused by:' prefix. So whenever {@linkplain #isCauseLine()}
168      * returns true, this returns true as well.
169      *
170      * @return true if the current line contained the exception message with or
171      * without the cause-by prefix; false, else
172      */
173     boolean isExceptionMessageLine ()
174     {
1750       return (mIsExceptionMessageLine || mIsCauseLine);
176     }
177  
178     /**
179      * Gets the exception message if the last line has been a cause line or a
180      * exception message line.
181      *
182      * @return Returns the exception message.
183      *
184      * @throws IllegalStateException if the recent line was not a cause line or
185      * exception message line.
186      */
187     String getExceptionMessage ()
188     {
1890       if (! (mIsCauseLine || mIsExceptionMessageLine))
190        {
1910          throw new IllegalStateException("The current line did not contain the "
192                 + "exception message");
193        }
1940       return mExceptionText.toString();
195     }
196  
197     /**
198      * Gets flag whether the current line is an at ... line.
199      *
200      * @return true if the current line is an at ... line; false, else.
201      */
202     boolean isLocationLine ()
203     {
2040       return mIsLocationLine;
205     }
206  
207     /**
208      * Gets the class name from an at-line.
209      *
210      * @return class name of an at-line
211      *
212      * @throws IllegalStateException if the recent line is not an at-line.
213      */
214     String getClassName ()
215     {
2160(3)      if (! mIsLocationLine)
217        {
2180          throw new IllegalStateException(CURRENT_LINE_ERROR_TEXT
219                 + "'at ...' line");
220        }
2210       return mClassName.toString();
222     }
223  
224     /**
225      * Gets the method name from an at-line.
226      *
227      * @return method of an at-line
228      *
229      * @throws IllegalStateException if the recent line is not an at-line.
230      */
231     String getMethodName ()
232     {
2330       if (! mIsLocationLine)
234        {
2350          throw new IllegalStateException(CURRENT_LINE_ERROR_TEXT
236                 + "'at ...' line");
237        }
2380       return mMethodName.toString();
239     }
240  
241     /**
242      * Gests the line info of an at-line. This might not be accessible, in which
243      * case 0 is returned.
244      *
245      * @return line information of at-line or 0 if no such.
246      *
247      * @throws IllegalStateException if the recent line is not an at-line.
248      */
249     int getLine ()
250     {
2510       if (! mIsLocationLine)
252        {
2530          throw new IllegalStateException(CURRENT_LINE_ERROR_TEXT
254                 + "'at ...' line");
255        }
2560       return mLine;
257     }
258  
259     /**
260      * Gets flag whether the current line is an ... nnn more line.
261      *
262      * @return true if the current line is an ... more line; false, else.
263      */
264     boolean isMoreLine ()
265     {
2660       return mIsMoreLine;
267     }
268  
269     /**
270      * Gets the number of stack trace items being concentrated into the more
271      * line.
272      *
273      * @return number of stack trace lines being neglected.
274      *
275      * @throws IllegalStateException if the recent line was not a more-line.
276      */
277     int getMoreLines ()
278     {
2790       if (! mIsMoreLine)
280        {
2810          throw new IllegalStateException(CURRENT_LINE_ERROR_TEXT
282                 + "'... nnn more' line");
283        }
2840       return mMoreLines;
285     }
286  }

Findings in this File

c (1) 41 : 0 Type Javadoc comment is missing an @author tag.
c (2) 134 : 33 Use bitwise inversion to invert boolean values
i (3) 216 : 0 Confusing to have methods org.jcoderz.commons.logging.StackTraceInfo.getClassName() and org.jcoderz.phoenix.findbugs.jaxb.impl.ClassTypeImpl.getClassname()