From 2489b18c86aa49a88832883f52bbe5282d79489b Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Wed, 9 Sep 2015 15:33:02 +0000 Subject: [PATCH] LUCENE-6791: sketchy MockFileSystem reflection should be in AccessController block git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1702038 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/mockfile/FilterFileChannel.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterFileChannel.java b/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterFileChannel.java index 8a09915a535..7a32bcdffd3 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterFileChannel.java +++ b/lucene/test-framework/src/java/org/apache/lucene/mockfile/FilterFileChannel.java @@ -26,6 +26,8 @@ import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Objects; /** @@ -137,21 +139,26 @@ public class FilterFileChannel extends FileChannel { @Override protected void implCloseChannel() throws IOException { // our only way to call delegate.implCloseChannel() - for (Class clazz = delegate.getClass(); clazz != null; clazz = clazz.getSuperclass()) { - final Method method; - try { - method = clazz.getDeclaredMethod("implCloseChannel"); - } catch (NoSuchMethodException e) { - continue; + AccessController.doPrivileged(new PrivilegedAction() { + @Override + public Void run() { + for (Class clazz = delegate.getClass(); clazz != null; clazz = clazz.getSuperclass()) { + final Method method; + try { + method = clazz.getDeclaredMethod("implCloseChannel"); + } catch (NoSuchMethodException e) { + continue; + } + try { + method.setAccessible(true); + method.invoke(delegate); + return null; + } catch (ReflectiveOperationException e) { + throw new IOError(e); + } + } + throw new AssertionError(); } - try { - method.setAccessible(true); - method.invoke(delegate); - return; - } catch (ReflectiveOperationException e) { - throw new IOError(e); - } - } - throw new AssertionError(); + }); } }