View Javadoc
1   /* Jackson JSON-processor.
2    *
3    * Copyright (c) 2007- Tatu Saloranta, tatu.saloranta@iki.fi
4    */
5   
6   package edu.internet2.middleware.grouperClientExt.com.fasterxml.jackson.core;
7   
8   /**
9    * Intermediate base class for all problems encountered when
10   * processing (parsing, generating) JSON content
11   * that are not pure I/O problems.
12   * Regular {@link java.io.IOException}s will be passed through as is.
13   * Sub-class of {@link java.io.IOException} for convenience.
14   *<p>
15   * Since Jackson 2.12 extends intermediate {@link JacksonException} type
16   * instead of directly extending {@link java.io.IOException}.
17   */
18  public class JsonProcessingException extends JacksonException
19  {
20      private final static long serialVersionUID = 123; // eclipse complains otherwise
21  
22      protected JsonLocation _location;
23  
24      protected JsonProcessingException(String msg, JsonLocation loc, Throwable rootCause) {
25          super(msg, rootCause);
26          _location = loc;
27      }
28  
29      protected JsonProcessingException(String msg) {
30          super(msg);
31      }
32  
33      protected JsonProcessingException(String msg, JsonLocation loc) {
34          this(msg, loc, null);
35      }
36  
37      protected JsonProcessingException(String msg, Throwable rootCause) {
38          this(msg, null, rootCause);
39      }
40  
41      protected JsonProcessingException(Throwable rootCause) {
42          this(null, null, rootCause);
43      }
44  
45      /*
46      /**********************************************************************
47      /* Extended API
48      /**********************************************************************
49       */
50  
51      @Override
52      public JsonLocation getLocation() { return _location; }
53  
54      /**
55       * Method that allows to remove context information from this exception's message.
56       * Useful when you are parsing security-sensitive data and don't want original data excerpts
57       * to be present in Jackson parser error messages.
58       *
59       * @since 2.9
60       */
61      public void clearLocation() { _location = null; }
62  
63      /**
64       * Method that allows accessing the original "message" argument,
65       * without additional decorations (like location information)
66       * that overridden {@link #getMessage} adds.
67       *
68       * @return Original message passed in constructor
69       *
70       * @since 2.1
71       */
72      @Override
73      public String getOriginalMessage() { return super.getMessage(); }
74  
75      /**
76       * Method that allows accessing underlying processor that triggered
77       * this exception; typically either {@link JsonParser} or {@link JsonGenerator}
78       * for exceptions that originate from streaming API.
79       * Note that it is possible that `null` may be returned if code throwing
80       * exception either has no access to processor; or has not been retrofitted
81       * to set it; this means that caller needs to take care to check for nulls.
82       * Subtypes override this method with co-variant return type, for more
83       * type-safe access.
84       * 
85       * @return Originating processor, if available; null if not.
86       *
87       * @since 2.7
88       */
89      @Override
90      public Object getProcessor() { return null; }
91  
92      /*
93      /**********************************************************************
94      /* Methods for sub-classes to use, override
95      /**********************************************************************
96       */
97      
98      /**
99       * Accessor that sub-classes can override to append additional
100      * information right after the main message, but before
101      * source location information.
102      *
103      * @return Message suffix assigned, if any; {@code null} if none
104      */
105     protected String getMessageSuffix() { return null; }
106 
107     /*
108     /**********************************************************************
109     /* Overrides of standard methods
110     /**********************************************************************
111      */
112 
113     /**
114      * Default implementation overridden so that we can add location information
115      *
116      * @return Original {@code message} preceded by optional prefix and followed by
117      *   location information, message and location information separated by a linefeed
118      */
119     @Override public String getMessage() {
120         String msg = super.getMessage();
121         if (msg == null) {
122             msg = "N/A";
123         }
124         JsonLocation loc = getLocation();
125         String suffix = getMessageSuffix();
126         // mild optimization, if nothing extra is needed:
127         if (loc != null || suffix != null) {
128             StringBuilder sb = new StringBuilder(100);
129             sb.append(msg);
130             if (suffix != null) {
131                 sb.append(suffix);
132             }
133             if (loc != null) {
134                 sb.append('\n');
135                 sb.append(" at ");
136                 sb.append(loc.toString());
137             }
138             msg = sb.toString();
139         }
140         return msg;
141     }
142 
143     @Override public String toString() { return getClass().getName()+": "+getMessage(); }
144 }