ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/dbcp/pool2/impl/ThrowableCallStack.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/dbcp/pool2/impl/ThrowableCallStack.java
Status
scanned
Type
file
Name
ThrowableCallStack.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3681 (3.6 KB)
MD5
f3b6ed3361b80cdcec7d54ec05c16b5a
SHA1
7392b1c26dab5364463987ee28bf1709f80dfd0d
SHA256
b71db6e1ee1f5bfcc34c928f78b7f1c15d47670a4f953a54a4e9c6ef0628f474
SHA512

      
    
SHA1_git
2a789aee24d64c36fa463ed305332b0be4527cfb
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ThrowableCallStack.java | 3.6 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.dbcp.pool2.impl; import java.io.PrintWriter; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.time.Instant; /** * CallStack strategy that uses the stack trace from a {@link Throwable}. This * strategy provides call stack method names and other metadata in addition to * the call stack of classes. * * @see Throwable#fillInStackTrace() * @since 2.4.3 */ public class ThrowableCallStack implements CallStack { /** * A snapshot of a throwable. */ private static final class Snapshot extends Throwable { private static final long serialVersionUID = 1L; private final Instant timestamp; /** * Constructs a new instance with its message set to the now instant. */ private Snapshot() { this(Instant.now()); } /** * Constructs a new instance and use the timestamp as the message with using {@link DateTimeFormatter#ISO_INSTANT} for more precision. * * @param timestamp normally the now instant. */ private Snapshot(final Instant timestamp) { super(timestamp.toString()); this.timestamp = timestamp; } } private final String messageFormat; // We keep the SimpleDateFormat for backward compatibility instead of a DateTimeFormatter. //@GuardedBy("dateFormat") private final DateFormat dateFormat; private volatile Snapshot snapshot; /** * Creates a new instance. * * @param messageFormat message format * @param useTimestamp whether to format the dates in the output message or not */ public ThrowableCallStack(final String messageFormat, final boolean useTimestamp) { this.messageFormat = messageFormat; this.dateFormat = useTimestamp ? new SimpleDateFormat(messageFormat) : null; } @Override public void clear() { snapshot = null; } @Override public void fillInStackTrace() { snapshot = new Snapshot(); } @Override public synchronized boolean printStackTrace(final PrintWriter writer) { final Snapshot snapshotRef = this.snapshot; if (snapshotRef == null) { return false; } final String message; if (dateFormat == null) { message = messageFormat; } else { synchronized (dateFormat) { // The throwable message is in {@link DateTimeFormatter#ISO_INSTANT} format for more precision. message = dateFormat.format(Long.valueOf(snapshotRef.timestamp.toEpochMilli())); } } writer.println(message); snapshotRef.printStackTrace(writer); return true; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
30.91
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-eb6b5ae0-4f88-4e9b-d67c-c6c8e733b1cd apache-2.0 Apache-2.0
URL Start line End line
https://www.apache.org/licenses/LICENSE-2.0 9 9