Author: remm Date: Thu Sep 29 10:20:27 2016 New Revision: 1762753 URL: http://svn.apache.org/viewvc?rev=1762753&view=rev Log: Java 9 compatibility for direct ByteBuffer cleaner.
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/ByteBufferUtils.java tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/ByteBufferUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/ByteBufferUtils.java?rev=1762753&r1=1762752&r2=1762753&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/ByteBufferUtils.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/ByteBufferUtils.java Thu Sep 29 10:20:27 2016 @@ -20,23 +20,41 @@ import java.lang.reflect.InvocationTarge 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; + public class ByteBufferUtils { + private static final StringManager sm = + StringManager.getManager(Constants.Package); + private static final Log log = LogFactory.getLog(ByteBufferUtils.class); + private static final Method cleanerMethod; private static final Method cleanMethod; static { + ByteBuffer tempBuffer = ByteBuffer.allocateDirect(0); + Method cleanerMethodLocal = null; + Method cleanMethodLocal = null; try { - ByteBuffer tempBuffer = ByteBuffer.allocateDirect(0); - cleanerMethod = tempBuffer.getClass().getMethod("cleaner"); - cleanerMethod.setAccessible(true); - Object cleanerObject = cleanerMethod.invoke(tempBuffer); - cleanMethod = cleanerObject.getClass().getMethod("clean"); - cleanMethod.invoke(cleanerObject); + cleanerMethodLocal = tempBuffer.getClass().getMethod("cleaner"); + cleanerMethodLocal.setAccessible(true); + Object cleanerObject = cleanerMethodLocal.invoke(tempBuffer); + if (cleanerObject instanceof Runnable) { + cleanMethodLocal = Runnable.class.getMethod("run"); + } else { + cleanMethodLocal = cleanerObject.getClass().getMethod("clean"); + } + cleanMethodLocal.invoke(cleanerObject); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { - throw new ExceptionInInitializerError(e); + log.warn(sm.getString("byteBufferUtils.cleaner"), e); + cleanerMethodLocal = null; + cleanMethodLocal = null; } + cleanerMethod = cleanerMethodLocal; + cleanMethod = cleanMethodLocal; } private ByteBufferUtils() { @@ -81,11 +99,13 @@ public class ByteBufferUtils { } public static void cleanDirectBuffer(ByteBuffer buf) { - try { - cleanMethod.invoke(cleanerMethod.invoke(buf)); - } catch (IllegalAccessException | IllegalArgumentException - | InvocationTargetException | SecurityException e) { - // Ignore + if (cleanMethod != null) { + try { + cleanMethod.invoke(cleanerMethod.invoke(buf)); + } catch (IllegalAccessException | IllegalArgumentException + | InvocationTargetException | SecurityException e) { + // Ignore + } } } Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties?rev=1762753&r1=1762752&r2=1762753&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties Thu Sep 29 10:20:27 2016 @@ -22,3 +22,5 @@ hexUtils.fromHex.nonHex=The input must c uDecoder.urlDecode.missingDigit=The % character must be followed by two hexademical digits uDecoder.convertHexDigit.notHex=[{0}] is not a hexadecimal digit uDecoder.urlDecode.uee=Unable to URL decode the specified input since the encoding [{0}] is not supported. + +byteBufferUtils.cleaner=Cannot use direct ByteBuffer cleaner, memory leaking may occur \ No newline at end of file Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1762753&r1=1762752&r2=1762753&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Thu Sep 29 10:20:27 2016 @@ -128,6 +128,9 @@ <fix> <bug>60173</bug>: Allow up to 64kB HTTP/2 header table size limit. (remm) </fix> + <fix> + Java 9 compatibility of direct ByteBuffer cleaner. (remm) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org