import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
* @throws IOException thrown on errors writing to the stream
*/
public abstract void write(OutputStream out) throws IOException;
+
+ @Internal
+ public DirectoryNode getDirectory() {
+ return directory;
+ }
}
java.util.TimeZone#getDefault() @ Do not use methods that depend on the current Local, either use Locale.ROOT or let the user define the local, see class LocaleUtil for details\r
java.util.Date#toString() @ Do not use methods that depend on the current Local, either use Locale.ROOT or let the user define the local, see class LocaleUtil for details\r
\r
-# disabled as there are still invocations that we could not remove easily\r
-#java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObject[], boolean) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9\r
-#java.lang.reflect.AccessibleObject#setAccessible(boolean) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9\r
-#java.lang.reflect.Method#invoke(java.lang.Object, java.lang.Object[]) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9\r
+# Disallow reflection on private object fields/methods\r
+java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObject[], boolean) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9\r
+java.lang.reflect.AccessibleObject#setAccessible(boolean) @ Reflection usage fails with SecurityManagers and likely will not work any more in Java 9\r
}
public abstract TextPieceTable getTextTable();
+
+ @Internal
+ public byte[] getMainStream() {
+ return _mainStream;
+ }
}
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import org.apache.poi.POIDocument;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFDocumentCore;
import org.apache.poi.hwpf.HWPFOldDocument;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
-import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.Beta;
public void dumpFileSystem() throws Exception
{
- java.lang.reflect.Field field = POIDocument.class
- .getDeclaredField( "directory" );
- field.setAccessible( true );
- DirectoryNode directoryNode = (DirectoryNode) field.get( _doc );
-
- System.out.println( dumpFileSystem( directoryNode ) );
+ System.out.println( dumpFileSystem( _doc.getDirectory() ) );
}
private String dumpFileSystem( DirectoryEntry directory )
HWPFDocument doc = (HWPFDocument) _doc;
- java.lang.reflect.Field fMainStream = HWPFDocumentCore.class
- .getDeclaredField( "_mainStream" );
- fMainStream.setAccessible( true );
- byte[] mainStream = (byte[]) fMainStream.get( _doc );
+ byte[] mainStream = _doc.getMainStream();
PlexOfCps binTable = new PlexOfCps( doc.getTableStream(), doc
.getFileInformationBlock().getFcPlcfbtePapx(), doc
}
}
- Method newParagraph = Paragraph.class.getDeclaredMethod(
- "newParagraph", Range.class, PAPX.class );
- newParagraph.setAccessible( true );
- java.lang.reflect.Field _props = Paragraph.class
- .getDeclaredField( "_props" );
- _props.setAccessible( true );
for ( PAPX papx : _doc.getParagraphTable().getParagraphs() )
{
if ( withProperties )
{
- Paragraph paragraph = (Paragraph) newParagraph.invoke( null,
- _doc.getOverallRange(), papx );
- System.out.println( _props.get( paragraph ) );
+ Paragraph paragraph = Paragraph.newParagraph( _doc.getOverallRange(), papx );
+ System.out.println( paragraph.getProps() );
}
if ( true )
public final static short SPRM_FADJUSTRIGHT = 0x2448;
@Internal
- static Paragraph newParagraph( Range parent, PAPX papx )
+ public static Paragraph newParagraph( Range parent, PAPX papx )
{
HWPFDocumentCore doc = parent._doc;
ListTables listTables = doc.getListTables();
{
return "Paragraph [" + getStartOffset() + "; " + getEndOffset() + ")";
}
+
+ @Internal
+ public ParagraphProperties getProps() {
+ return _props;
+ }
}
package org.apache.poi.hwpf.usermodel;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-
import org.apache.poi.hwpf.model.types.SEPAbstractType;
public final class SectionProperties extends SEPAbstractType
return copy;
}
-
- @Override
- public boolean equals( Object obj )
- {
- Field[] fields = SectionProperties.class.getSuperclass()
- .getDeclaredFields();
- AccessibleObject.setAccessible( fields, true );
- try
- {
- for ( int x = 0; x < fields.length; x++ )
- {
- Object obj1 = fields[x].get( this );
- Object obj2 = fields[x].get( obj );
- if ( obj1 == null && obj2 == null )
- {
- continue;
- }
- if ( obj1 == null || obj2 == null || !obj1.equals( obj2 ) )
- {
- return false;
- }
- }
- return true;
- }
- catch ( Exception e )
- {
- return false;
- }
- }
- @Override
- public int hashCode() {
- assert false : "hashCode not designed";
- return 42; // any arbitrary constant will do
- }
}
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import junit.framework.TestCase;
import org.apache.poi.hwpf.HWPFDocFixture;
+import org.apache.poi.util.SuppressForbidden;
public final class TestFileInformationBlock extends TestCase {
private FileInformationBlock _fileInformationBlock = null;
FileInformationBlock newFileInformationBlock = new FileInformationBlock(
buf);
- Field[] fields = FileInformationBlock.class.getSuperclass()
- .getDeclaredFields();
- AccessibleObject.setAccessible(fields, true);
+ final Field[] fields;
+ try {
+ fields = AccessController.doPrivileged(new PrivilegedExceptionAction<Field[]>() {
+ @Override
+ @SuppressForbidden("Test only")
+ public Field[] run() throws Exception {
+ final Field[] fields = FileInformationBlock.class.getSuperclass().getDeclaredFields();
+ AccessibleObject.setAccessible(fields, true);
+ return fields;
+ }
+ });
+ } catch (PrivilegedActionException pae) {
+ throw pae.getException();
+ }
for (int x = 0; x < fields.length; x++) {
assertEquals(fields[x].get(_fileInformationBlock),
}
});
} catch (PrivilegedActionException pae) {
- throw new AssertionError("Cannot access field '" + fieldName + "' of class " + clazz);
+ throw new RuntimeException("Cannot access field '" + fieldName + "' of class " + clazz, pae.getException());
}
}
}
});
} catch (PrivilegedActionException pae) {
- throw new AssertionError("Cannot access method '" + methodName + "' of class " + clazz);
+ throw new RuntimeException("Cannot access method '" + methodName + "' of class " + clazz, pae.getException());
}
}
}