@@ -48,6 +48,7 @@ public class LocationInfo implements java.io.Serializable {
48
48
* All available caller information, in the format
49
49
* <code>fully.qualified.classname.of.caller.methodName(Filename.java:line)</code>
50
50
*/
51
+ // ATTENTION: fullInfo is used to reconstruct the other fields post deserialization
51
52
public String fullInfo ;
52
53
53
54
/**
@@ -178,12 +179,33 @@ public LocationInfo(final String file, final String classname, final String meth
178
179
this .fullInfo = buf .toString ();
179
180
}
180
181
182
+
181
183
/**
182
184
* Return the fully qualified class name of the caller making the logging
183
185
* request.
184
186
*/
185
187
public String getClassName () {
186
- return className ;
188
+ if (fullInfo == null )
189
+ return NA ;
190
+ if (className != null ) {
191
+ return className ;
192
+ } else {
193
+ // Starting the search from '(' is safer because there is
194
+ // potentially a dot between the parentheses.
195
+ int iend = fullInfo .lastIndexOf ('(' );
196
+ if (iend == -1 )
197
+ className = NA ;
198
+ else {
199
+ iend = fullInfo .lastIndexOf ('.' , iend );
200
+ int ibegin = 0 ;
201
+
202
+ if (iend == -1 )
203
+ className = NA ;
204
+ else
205
+ className = this .fullInfo .substring (ibegin , iend );
206
+ }
207
+ return className ;
208
+ }
187
209
}
188
210
189
211
/**
@@ -193,6 +215,18 @@ public String getClassName() {
193
215
* This information is not always available.
194
216
*/
195
217
public String getFileName () {
218
+ if (fullInfo == null )
219
+ return NA ;
220
+ if (fileName == null ) {
221
+ int iend = fullInfo .lastIndexOf (':' );
222
+ if (iend == -1 )
223
+ fileName = NA ;
224
+ else {
225
+ int ibegin = fullInfo .lastIndexOf ('(' , iend - 1 );
226
+ fileName = this .fullInfo .substring (ibegin + 1 , iend );
227
+ }
228
+ }
229
+
196
230
return fileName ;
197
231
}
198
232
@@ -203,13 +237,33 @@ public String getFileName() {
203
237
* This information is not always available.
204
238
*/
205
239
public String getLineNumber () {
240
+ if (fullInfo == null )
241
+ return NA ;
242
+ if (lineNumber == null ) {
243
+ int iend = fullInfo .lastIndexOf (')' );
244
+ int ibegin = fullInfo .lastIndexOf (':' , iend - 1 );
245
+ if (ibegin == -1 )
246
+ lineNumber = NA ;
247
+ else
248
+ lineNumber = this .fullInfo .substring (ibegin + 1 , iend );
249
+ }
206
250
return lineNumber ;
207
251
}
208
252
209
253
/**
210
254
* Returns the method name of the caller.
211
255
*/
212
256
public String getMethodName () {
257
+ if (fullInfo == null )
258
+ return NA ;
259
+ if (methodName == null ) {
260
+ int iend = fullInfo .lastIndexOf ('(' );
261
+ int ibegin = fullInfo .lastIndexOf ('.' , iend );
262
+ if (ibegin == -1 )
263
+ methodName = NA ;
264
+ else
265
+ methodName = this .fullInfo .substring (ibegin + 1 , iend );
266
+ }
213
267
return methodName ;
214
268
}
215
269
}
0 commit comments