You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2017/01/05 16:32:45 UTC
[Bug 60556] New: IllegalArgumentException: The end () must not be
before the start ()
https://bz.apache.org/bugzilla/show_bug.cgi?id=60556
Bug ID: 60556
Summary: IllegalArgumentException: The end () must not be
before the start ()
Product: POI
Version: 3.15-FINAL
Hardware: PC
Status: NEW
Severity: major
Priority: P2
Component: HWPF
Assignee: dev@poi.apache.org
Reporter: ismaelgomezs@gmail.com
Target Milestone: ---
Created attachment 34596
--> https://bz.apache.org/bugzilla/attachment.cgi?id=34596&action=edit
File which the code fails
I'm extracting the text from a WordExtractor class (apache POI), but I have an
error for some .doc files. Here the code:
"
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
public class [class name]
{
public static void main(String... args) throws FileNotFoundException,
IOException, NullPointerException, OfficeXmlFileException {
File[] files = new File("[input path]").listFiles();
showFiles(files);
}
public static void showFiles(File[] files) throws
FileNotFoundException, IOException, NullPointerException,
OfficeXmlFileException {
File log = new File("[output name]/out.tsv");
for (File file : files) {
if (file.isDirectory()) {
//System.out.println("Directory/" + file.getName());
showFiles(file.listFiles()); // Calls same method
again.
} else {
String N = file.getName();
// caso .docx
if (N.toLowerCase().endsWith(".docx") &&
!N.toLowerCase().startsWith("~"))
{
System.out.println(file.getAbsolutePath());
XWPFDocument docx = new
XWPFDocument(new FileInputStream(file));
XWPFWordExtractor we = new
XWPFWordExtractor(docx);
String T =
we.getText().replaceAll("\\n", " ").replaceAll("\\r", " ");
// PARA ESCRIBIR EL ARCHIVO
try{
// if(!log.exists()){
// System.out.println("We had to
make a new file.");
// log.createNewFile();
// }
FileWriter fileWriter = new
FileWriter(log, true);
BufferedWriter bufferedWriter = new
BufferedWriter(fileWriter);
bufferedWriter.write(file.getAbsolutePath()+"\t"+T+"\n");
bufferedWriter.close();
} catch (IOException e) {
System.err.println("Problem writing .DOCX to the
file out.txt " + e.getMessage());
}
}
else {
if (N.toLowerCase().endsWith(".doc") &&
!N.toLowerCase().startsWith("~"))
{
System.out.println(file.getAbsolutePath());
HWPFDocument doc = new
HWPFDocument(new FileInputStream(file));
WordExtractor we = new
WordExtractor(doc);
//WordExtractor we = new
WordExtractor(new FileInputStream(file));
String T =
we.getText().replaceAll("\\n", " ").replaceAll("\\r", " ");
// PARA ESCRIBIR EL ARCHIVO
try{
// if(!log.exists()){
//
log.createNewFile();
// }
FileWriter fileWriter =
new FileWriter(log, true);
BufferedWriter
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write(file.getAbsolutePath()+"\t"+T+"\n");
bufferedWriter.close();
} catch (IOException e) {
System.err.println("Problem writing .DOC to the file out.txt " +
e.getMessage());
}
}
}
}
}
}
}
"
For most .docx and .doc files it's work fine.
The error message is:
Exception in thread "main" java.lang.RuntimeException:
java.lang.IllegalArgumentException: The end (4958) must not be before the start
(4990)
How can I fix it?
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 60556] IllegalArgumentException: The end () must not be before
the start ()
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60556
--- Comment #1 from ps26oct@gmail.com ---
The problem seems to be with the document and not the code and specifically
with the hidden bookmark with the name: "_Toc263095067". Apparently poi is
inferring the end of the bookmark to be located before the start. Deleting that
particular hidden bookmark makes everything work fine.
Let me know of any other corrective measures or any actual problem in the poi
code this highlights, if any.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 60556] IllegalArgumentException: The end () must not be before
the start ()
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60556
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Dominik Stadler <do...@gmx.at> ---
Seems to have been caused by a slightly broken document.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 60556] IllegalArgumentException: The end () must not be before
the start ()
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60556
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 60556] IllegalArgumentException: The end () must not be before
the start ()
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=60556
--- Comment #2 from ismaelgomezs@gmail.com ---
Thank you very much. That was the problem. Now it works fine!
Regards.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org