package org.apache.poi.hwpf.usermodel;
-import java.lang.ref.WeakReference;
import java.util.List;
import org.apache.poi.hwpf.HWPFDocument;
public static final int TYPE_UNDEFINED = 6;
/** Needed so inserts and deletes will ripple up through containing Ranges */
- private final WeakReference<Range> _parent;
+ private final Range _parent;
/** The starting character offset of this range. */
protected final int _start;
_paragraphs = _doc.getParagraphTable().getParagraphs();
_characters = _doc.getCharacterTable().getTextRuns();
_text = _doc.getText();
- _parent = new WeakReference<>(null);
+ _parent = null;
sanityCheckStartEnd();
}
_paragraphs = parent._paragraphs;
_characters = parent._characters;
_text = parent._text;
- _parent = new WeakReference<>(parent);
+ _parent = parent;
sanityCheckStartEnd();
sanityCheck();
}
_text.delete( _start, _end );
- Range parent = _parent.get();
+ Range parent = _parent;
if ( parent != null )
{
parent.adjustForInsert( -( _end - _start ) );
}
Range r = paragraph;
- if (r._parent.get() != this) {
+ if (r._parent != this) {
throw new IllegalArgumentException("This paragraph is not a child of this range instance");
}
_end += length;
reset();
- Range parent = _parent.get();
+ Range parent = _parent;
if (parent != null) {
parent.adjustForInsert(length);
}
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.apache.poi.util.HexDump;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static org.junit.Assert.assertTrue;
/**
- * Bug 47563 - Exception when working with table
+ * Bug 47563 - Exception when working with table
*/
@RunWith(Parameterized.class)
public class TestBug47563 {
}
String text = range.text();
+ String textBytes = HexDump.toHex(text.getBytes(StandardCharsets.UTF_8));
int mustBeAfter = 0;
for (int i = 0; i < rows * columns; i++) {
int next = text.indexOf(Integer.toString(i), mustBeAfter);
- assertTrue("Test with " + rows + "/" + columns + ": Should not find " + i +
- " but found it at " + next + " with " + mustBeAfter + " in " + text + "\n" +
+ assertTrue("Test with " + rows + "/" + columns + ": Should find " + i +
+ " but did not find it (" + next + ") with " + mustBeAfter + " in " + textBytes + "\n" +
text.indexOf(Integer.toString(i), mustBeAfter),
next != -1);
mustBeAfter = next;