ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/util/buf/ByteBufferUtilsUnsafe.java

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

      
    
Rootfs path

      
    
Size
3462 (3.4 KB)
MD5
ebe3097dd52f3db28fd0e259e67926b2
SHA1
af583444085604738d3a3cc712e78366033d709e
SHA256
bf6aaf76a56693eb33fab72d11b39dc4c147d160cab1f94954dcd7b0c6b23129
SHA512

      
    
SHA1_git
0b01fe7042290094aa1b2ab91e321b592aeb25ed
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
ByteBufferUtilsUnsafe.java | 3.4 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 * * http://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.util.buf; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.ByteBuffer; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.res.StringManager; /* * This functionality is in a separate class so it is only loaded if cleanDirectBuffer() is called. This is because the * use of unsafe triggers an unavoidable warning with Java 24. */ class ByteBufferUtilsUnsafe { private static final StringManager sm = StringManager.getManager(ByteBufferUtilsUnsafe.class); private static final Log log = LogFactory.getLog(ByteBufferUtilsUnsafe.class); private static final Object unsafe; private static final Method invokeCleanerMethod; static { ByteBuffer tempBuffer = ByteBuffer.allocateDirect(0); Object unsafeLocal; Method invokeCleanerMethodLocal; try { Class<?> clazz = Class.forName("sun.misc.Unsafe"); Field theUnsafe = clazz.getDeclaredField("theUnsafe"); theUnsafe.setAccessible(true); unsafeLocal = theUnsafe.get(null); invokeCleanerMethodLocal = clazz.getMethod("invokeCleaner", ByteBuffer.class); invokeCleanerMethodLocal.invoke(unsafeLocal, tempBuffer); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException | NoSuchFieldException e) { log.warn(sm.getString("byteBufferUtils.cleaner"), e); unsafeLocal = null; invokeCleanerMethodLocal = null; } unsafe = unsafeLocal; invokeCleanerMethod = invokeCleanerMethodLocal; } private ByteBufferUtilsUnsafe() { // Hide the default constructor since this is a utility class. } /** * Clean specified direct buffer. This will cause an unavoidable warning on Java 24 and newer. * * @param buf the buffer to clean */ static void cleanDirectBuffer(ByteBuffer buf) { if (invokeCleanerMethod != null) { try { invokeCleanerMethod.invoke(unsafe, buf); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException e) { if (log.isDebugEnabled()) { log.debug(sm.getString("byteBufferUtils.cleaner"), e); } } } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
35.1
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9