Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 19F7F188E9 for ; Mon, 9 Nov 2015 09:06:04 +0000 (UTC) Received: (qmail 17262 invoked by uid 500); 9 Nov 2015 09:06:03 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 17224 invoked by uid 500); 9 Nov 2015 09:06:03 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 17215 invoked by uid 99); 9 Nov 2015 09:06:03 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Nov 2015 09:06:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 75931180440 for ; Mon, 9 Nov 2015 09:06:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.99 X-Spam-Level: X-Spam-Status: No, score=0.99 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id NIlBzSBKmkFA for ; Mon, 9 Nov 2015 09:06:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 4570321270 for ; Mon, 9 Nov 2015 09:06:02 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id CE635E043E for ; Mon, 9 Nov 2015 09:06:01 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 9DE4E3A071A for ; Mon, 9 Nov 2015 09:06:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1713350 - /poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java Date: Mon, 09 Nov 2015 09:06:01 -0000 To: commits@poi.apache.org From: uschindler@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151109090601.9DE4E3A071A@svn01-us-west.apache.org> Author: uschindler Date: Mon Nov 9 09:06:01 2015 New Revision: 1713350 URL: http://svn.apache.org/viewvc?rev=1713350&view=rev Log: Use Lucene's unmapping code inside AccessController.doPrivileged() for unmapping mapped byte buffers. Modified: poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java Modified: poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java?rev=1713350&r1=1713349&r2=1713350&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java (original) +++ poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java Mon Nov 9 09:06:01 2015 @@ -22,21 +22,27 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import java.io.RandomAccessFile; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.nio.channels.WritableByteChannel; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.List; import org.apache.poi.util.IOUtils; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; +import org.apache.poi.util.SuppressForbidden; /** * A POIFS {@link DataSource} backed by a File */ public class FileBackedDataSource extends DataSource { + private final static POILogger logger = POILogFactory.getLogger( FileBackedDataSource.class ); + private FileChannel channel; private boolean writable; // remember file base, which needs to be closed too @@ -155,26 +161,23 @@ public class FileBackedDataSource extend // need to use reflection to avoid depending on the sun.nio internal API // unfortunately this might break silently with newer/other Java implementations, // but we at least have unit-tests which will indicate this when run on Windows - private static void unmap(ByteBuffer bb) { - Class fcClass = bb.getClass(); - try { - // invoke bb.cleaner().clean(), but do not depend on sun.nio - // interfaces - Method cleanerMethod = fcClass.getDeclaredMethod("cleaner"); - cleanerMethod.setAccessible(true); - Object cleaner = cleanerMethod.invoke(bb); - Method cleanMethod = cleaner.getClass().getDeclaredMethod("clean"); - cleanMethod.invoke(cleaner); - } catch (NoSuchMethodException e) { - // e.printStackTrace(); - } catch (SecurityException e) { - // e.printStackTrace(); - } catch (IllegalAccessException e) { - // e.printStackTrace(); - } catch (IllegalArgumentException e) { - // e.printStackTrace(); - } catch (InvocationTargetException e) { - // e.printStackTrace(); - } + private static void unmap(final ByteBuffer buffer) { + AccessController.doPrivileged(new PrivilegedAction() { + @Override + @SuppressForbidden("Java 9 Jigsaw whitelists access to sun.misc.Cleaner, so setAccessible works") + public Void run() { + try { + final Method getCleanerMethod = buffer.getClass().getMethod("cleaner"); + getCleanerMethod.setAccessible(true); + final Object cleaner = getCleanerMethod.invoke(buffer); + if (cleaner != null) { + cleaner.getClass().getMethod("clean").invoke(cleaner); + } + } catch (Exception e) { + logger.log(POILogger.WARN, "Unable to unmap memory mapped ByteBuffer.", e); + } + return null; // Void + } + }); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org