You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2016/06/01 08:05:08 UTC
svn commit: r1746411 - in /poi/trunk/src:
java/org/apache/poi/poifs/nio/FileBackedDataSource.java
testcases/org/apache/poi/poifs/nio/TestDataSource.java
testcases/org/apache/poi/util/TestHexDump.java
Author: centic
Date: Wed Jun 1 08:05:07 2016
New Revision: 1746411
URL: http://svn.apache.org/viewvc?rev=1746411&view=rev
Log:
The changes for using AccessController/SecurityManager also added a log which now spams a lot if log is enabled in integration-tests, reduce it a bit by not trying to call "cleaner()" on HeapByteBuffer which does not have it for sure
Modified:
poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
poi/trunk/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java
poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.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=1746411&r1=1746410&r2=1746411&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 Wed Jun 1 08:05:07 2016
@@ -162,22 +162,27 @@ public class FileBackedDataSource extend
// 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(final ByteBuffer buffer) {
- AccessController.doPrivileged(new PrivilegedAction<Void>() {
- @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
- }
- });
+ // not necessary for HeapByteBuffer, avoid lots of log-output on this class
+ if(buffer.getClass().getName().endsWith("HeapByteBuffer")) {
+ return;
+ }
+
+ AccessController.doPrivileged(new PrivilegedAction<Void>() {
+ @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
+ }
+ });
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java?rev=1746411&r1=1746410&r2=1746411&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/nio/TestDataSource.java Wed Jun 1 08:05:07 2016
@@ -19,20 +19,14 @@
package org.apache.poi.poifs.nio;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-
+import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.TempFile;
-import junit.framework.TestCase;
+import java.io.*;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
/**
* Tests for the datasource implementations
@@ -121,7 +115,7 @@ public class TestDataSource extends Test
}
}
- private void writeDataToFile(File temp) throws FileNotFoundException, IOException {
+ private void writeDataToFile(File temp) throws IOException {
OutputStream str = new FileOutputStream(temp);
try {
InputStream in = data.openResourceAsStream("Notes.ole2");
@@ -153,11 +147,11 @@ public class TestDataSource extends Test
assertEquals(0, bs.position());
assertEquals(0xd0 - 256, bs.get(0));
assertEquals(0xcf - 256, bs.get(1));
- assertEquals(0x11 - 000, bs.get(2));
+ assertEquals(0x11, bs.get(2));
assertEquals(0xe0 - 256, bs.get(3));
assertEquals(0xd0 - 256, bs.get());
assertEquals(0xcf - 256, bs.get());
- assertEquals(0x11 - 000, bs.get());
+ assertEquals(0x11, bs.get());
assertEquals(0xe0 - 256, bs.get());
// Mid way through
@@ -179,11 +173,12 @@ public class TestDataSource extends Test
// Can't go off the end
try {
- bs = ds.read(4, 8192);
+ ds.read(4, 8192);
if(!writeable) {
fail("Shouldn't be able to read off the end of the file");
}
} catch (IllegalArgumentException e) {
+ // expected here
}
}
@@ -228,13 +223,17 @@ public class TestDataSource extends Test
try {
bs.get();
fail("Shouldn't be able to read off the end");
- } catch(BufferUnderflowException e) {}
+ } catch(BufferUnderflowException e) {
+ // expected here
+ }
// Past the end
try {
- bs = ds.read(4, 256);
+ ds.read(4, 256);
fail("Shouldn't be able to read off the end");
- } catch(IndexOutOfBoundsException e) {}
+ } catch(IndexOutOfBoundsException e) {
+ // expected here
+ }
// Overwrite
Modified: poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java?rev=1746411&r1=1746410&r2=1746411&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java Wed Jun 1 08:05:07 2016
@@ -125,13 +125,12 @@ public class TestHexDump {
}
}
obj[17] = chrs.toString();
- format.append("%18$s"+HexDump.EOL);
+ format.append("%18$s").append(HexDump.EOL);
String str = String.format(LocaleUtil.getUserLocale(), format.toString(), obj);
strExp.append(str);
}
- byte bytesExp[] = strExp.toString().getBytes(HexDump.UTF8);
- return bytesExp;
+ return strExp.toString().getBytes(HexDump.UTF8);
}
@Test
@@ -157,7 +156,7 @@ public class TestHexDump {
assertEquals("FFFF", HexDump.toHex((short)0xFFFF));
- assertEquals("00000000000004D2", HexDump.toHex(1234l));
+ assertEquals("00000000000004D2", HexDump.toHex(1234L));
assertEquals("0xFE", HexDump.byteToHex(-2));
assertEquals("0x25", HexDump.byteToHex(37));
@@ -185,18 +184,28 @@ public class TestHexDump {
@Test(expected=ArrayIndexOutOfBoundsException.class)
public void testDumpToStringOutOfIndex1() throws Exception {
- HexDump.dump(new byte[ 1 ], 0, -1);
+ HexDump.dump(new byte[1], 0, -1);
}
@Test(expected=ArrayIndexOutOfBoundsException.class)
public void testDumpToStringOutOfIndex2() throws Exception {
- HexDump.dump(new byte[ 1 ], 0, 2);
+ HexDump.dump(new byte[1], 0, 2);
}
+ @Test(expected=ArrayIndexOutOfBoundsException.class)
public void testDumpToStringOutOfIndex3() throws Exception {
- HexDump.dump(new byte[ 1 ], 0, 1);
+ HexDump.dump(new byte[1], 0, 1);
+ }
+
+ @Test
+ public void testDumpToStringNoDataEOL1() throws Exception {
+ HexDump.dump(new byte[0], 0, 1);
}
+ @Test
+ public void testDumpToStringNoDataEOL2() throws Exception {
+ HexDump.dump(new byte[0], 0, 0);
+ }
@Test
public void testDumpToPrintStream() throws IOException {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org