510 parameters[i] = in.readObject(); 511 } 512 } 513 // If necessary, try to regenerate the resource bundle. 514 if (resourceBundleName != null) { 515 try { 516 resourceBundle = ResourceBundle.getBundle(resourceBundleName); 517 } catch (MissingResourceException ex) { 518 // This is not a good place to throw an exception, 519 // so we simply leave the resourceBundle null. 520 resourceBundle = null; 521 } 522 } 523 524 needToInferCaller = false; 525 } 526 527 // Private method to infer the caller's class and method names 528 private void inferCaller() { 529 needToInferCaller = false; 530 JavaLangAccess access = SharedSecrets.getJavaLangAccess(); 531 Throwable throwable = new Throwable(); 532 int depth = access.getStackTraceDepth(throwable); 533 534 boolean lookingForLogger = true; 535 for (int ix = 0; ix < depth; ix++) { 536 // Calling getStackTraceElement directly prevents the VM 537 // from paying the cost of building the entire stack frame. 538 StackTraceElement frame = 539 access.getStackTraceElement(throwable, ix); 540 String cname = frame.getClassName(); 541 boolean isLoggerImpl = isLoggerImplFrame(cname); 542 if (lookingForLogger) { 543 // Skip all frames until we have found the first logger frame. 544 if (isLoggerImpl) { 545 lookingForLogger = false; 546 } 547 } else { 548 if (!isLoggerImpl) { 549 // skip reflection call 550 if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) { 551 // We've found the relevant frame. 552 setSourceClassName(cname); 553 setSourceMethodName(frame.getMethodName()); 554 return; 555 } 556 } 557 } 558 } 559 // We haven't found a suitable frame, so just punt. This is 560 // OK as we are only committed to making a "best effort" here. 561 } 562 563 private boolean isLoggerImplFrame(String cname) { 564 // the log record could be created for a platform logger 565 return (cname.equals("java.util.logging.Logger") || 566 cname.startsWith("java.util.logging.LoggingProxyImpl") || 567 cname.startsWith("sun.util.logging.")); 568 } 569 } | 510 parameters[i] = in.readObject(); 511 } 512 } 513 // If necessary, try to regenerate the resource bundle. 514 if (resourceBundleName != null) { 515 try { 516 resourceBundle = ResourceBundle.getBundle(resourceBundleName); 517 } catch (MissingResourceException ex) { 518 // This is not a good place to throw an exception, 519 // so we simply leave the resourceBundle null. 520 resourceBundle = null; 521 } 522 } 523 524 needToInferCaller = false; 525 } 526 527 // Private method to infer the caller's class and method names 528 private void inferCaller() { 529 needToInferCaller = false; 530 // Skip all frames until we have found the first logger frame. 531 StackTraceElement frame = 532 Thread.firstCaller(e -> {return !isLoggerImplFrame(e.getClassName()); }, 533 StackFrameInfo::stackTraceElement); 534 if (frame != null) { 535 setSourceClassName(frame.getClassName()); 536 setSourceMethodName(frame.getMethodName()); 537 } 538 // We haven't found a suitable frame, so just punt. This is 539 // OK as we are only committed to making a "best effort" here. 540 } 541 542 private boolean isLoggerImplFrame(String cname) { 543 // the log record could be created for a platform logger 544 return (cname.startsWith("java.util.logging.") || 545 cname.startsWith("sun.util.logging.")); 546 } 547 } |