@@ -152,12 +152,7 @@ final public static FormattingTuple format(final String messagePattern, Object a
152
152
}
153
153
154
154
final public static FormattingTuple arrayFormat (final String messagePattern , final Object [] argArray ) {
155
- Throwable throwableCandidate = MessageFormatter .getThrowableCandidate (argArray );
156
- Object [] args = argArray ;
157
- if (throwableCandidate != null ) {
158
- args = MessageFormatter .trimmedCopy (argArray );
159
- }
160
- return arrayFormat (messagePattern , args , throwableCandidate );
155
+ return arrayFormat (messagePattern , argArray , null );
161
156
}
162
157
163
158
/**
@@ -166,26 +161,40 @@ final public static FormattingTuple arrayFormat(final String messagePattern, fin
166
161
* @param messagePattern
167
162
* @param argArray
168
163
*/
164
+ @ Deprecated
169
165
final public static String basicArrayFormat (final String messagePattern , final Object [] argArray ) {
170
166
FormattingTuple ft = arrayFormat (messagePattern , argArray , null );
171
167
return ft .getMessage ();
172
168
}
173
169
174
- public static String basicArrayFormat (NormalizedParameters np ) {
175
- return basicArrayFormat (np .getMessage (), np .getArguments ());
170
+ /** Resolves throwable to be used in log message.
171
+ *
172
+ * @param index index of first array entry that was not bound to format placeholder
173
+ */
174
+ final static Throwable resolveThrowable (final Object [] argArray , final int index , final Throwable throwable ) {
175
+ if (throwable != null ) {
176
+ return throwable ;
177
+ }
178
+ if (argArray != null && argArray .length > index ) {
179
+ final Object lastEntry = argArray [argArray .length - 1 ];
180
+ if (lastEntry instanceof Throwable ) {
181
+ return (Throwable ) lastEntry ;
182
+ }
183
+ }
184
+ return null ;
176
185
}
177
186
178
187
final public static FormattingTuple arrayFormat (final String messagePattern , final Object [] argArray , Throwable throwable ) {
179
188
180
189
if (messagePattern == null ) {
181
- return new FormattingTuple (null , argArray , throwable );
190
+ return new FormattingTuple (null , resolveThrowable ( argArray , 0 , throwable ) );
182
191
}
183
192
184
193
if (argArray == null ) {
185
- return new FormattingTuple (messagePattern );
194
+ return new FormattingTuple (messagePattern , throwable );
186
195
}
187
196
188
- int i = 0 ;
197
+ int i = 0 ; // index in the pattern
189
198
int j ;
190
199
// use string builder for better multicore performance
191
200
StringBuilder sbuf = new StringBuilder (messagePattern .length () + 50 );
@@ -198,11 +207,11 @@ final public static FormattingTuple arrayFormat(final String messagePattern, fin
198
207
if (j == -1 ) {
199
208
// no more variables
200
209
if (i == 0 ) { // this is a simple string
201
- return new FormattingTuple (messagePattern , argArray , throwable );
210
+ return new FormattingTuple (messagePattern , resolveThrowable ( argArray , L , throwable ) );
202
211
} else { // add the tail string which contains no variables and return
203
212
// the result.
204
213
sbuf .append (messagePattern , i , messagePattern .length ());
205
- return new FormattingTuple (sbuf .toString (), argArray , throwable );
214
+ return new FormattingTuple (sbuf .toString (), resolveThrowable ( argArray , L , throwable ) );
206
215
}
207
216
} else {
208
217
if (isEscapedDelimeter (messagePattern , j )) {
@@ -229,7 +238,7 @@ final public static FormattingTuple arrayFormat(final String messagePattern, fin
229
238
}
230
239
// append the characters following the last {} pair.
231
240
sbuf .append (messagePattern , i , messagePattern .length ());
232
- return new FormattingTuple (sbuf .toString (), argArray , throwable );
241
+ return new FormattingTuple (sbuf .toString (), throwable );
233
242
}
234
243
235
244
final static boolean isEscapedDelimeter (String messagePattern , int delimeterStartIndex ) {
@@ -402,29 +411,4 @@ private static void doubleArrayAppend(StringBuilder sbuf, double[] a) {
402
411
}
403
412
sbuf .append (']' );
404
413
}
405
-
406
- /**
407
- * Helper method to determine if an {@link Object} array contains a {@link Throwable} as last element
408
- *
409
- * @param argArray
410
- * The arguments off which we want to know if it contains a {@link Throwable} as last element
411
- * @return if the last {@link Object} in argArray is a {@link Throwable} this method will return it,
412
- * otherwise it returns null
413
- */
414
- public static Throwable getThrowableCandidate (final Object [] argArray ) {
415
- return NormalizedParameters .getThrowableCandidate (argArray );
416
- }
417
-
418
- /**
419
- * Helper method to get all but the last element of an array
420
- *
421
- * @param argArray
422
- * The arguments from which we want to remove the last element
423
- *
424
- * @return a copy of the array without the last element
425
- */
426
- public static Object [] trimmedCopy (final Object [] argArray ) {
427
- return NormalizedParameters .trimmedCopy (argArray );
428
- }
429
-
430
414
}
0 commit comments