File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
utilcode/src/main/java/com/blankj/utilcode/util Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -213,7 +213,22 @@ private static TagHead processTagAndHead(String tag) {
213213 final StackTraceElement [] stackTrace = new Throwable ().getStackTrace ();
214214 StackTraceElement targetElement = stackTrace [3 ];
215215 String fileName = targetElement .getFileName ();
216- String className = fileName .substring (0 , fileName .indexOf ('.' ));
216+ String className ;
217+ if (fileName == null ) {// 混淆可能会导致获取为空 加-keepattributes SourceFile,LineNumberTable
218+ className = targetElement .getClassName ();
219+ String [] classNameInfo = className .split ("\\ ." );
220+ if (classNameInfo .length > 0 ) {
221+ className = classNameInfo [classNameInfo .length - 1 ];
222+ }
223+ int index = className .indexOf ('$' );
224+ if (index != -1 ) {
225+ className = className .substring (0 , index );
226+ }
227+ fileName = className + ".java" ;
228+ } else {
229+ int index = fileName .indexOf ('.' );// 混淆可能导致文件名被改变从而找不到"."
230+ className = index == -1 ? fileName : fileName .substring (0 , index );
231+ }
217232 if (sTagIsSpace ) tag = isSpace (tag ) ? className : tag ;
218233 if (sLogHeadSwitch ) {
219234 String tName = Thread .currentThread ().getName ();
You can’t perform that action at this time.
0 commit comments