英文:
Java error line number not being reported and debugging not allowed
问题
我有一个Java项目,其中我正在使用iText 2.1.7(一个相当旧的版本,我知道,但这是一个遗留项目)来处理一些PDF文件。为了调整和调试一些与字体相关的问题,我创建了如下的测试代码:
@Test
public void testGeneratePDF() throws FileNotFoundException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
document.open();
String fontPath = this.getClass().getClassLoader().getResource("NotoSansCJK.ttc").getPath();
FontFactory.register(fontPath);
Set<String> fonts = new TreeSet<String>(FontFactory.getRegisteredFonts());
for (String fontname : fonts) {
showFontInfo(document, fontname);
}
document.close();
}
当我运行这个测试时,我得到以下的错误跟踪信息:
ExceptionConverter: com.lowagie.text.DocumentException: /Users/jdebenitocalzada/dev/myproject/target/test-classes/NotoSansCJK.ttc is not a valid TTF file.
at com.lowagie.text.pdf.EnumerateTTC.findNames(Unknown Source)
at com.lowagie.text.pdf.EnumerateTTC.<init>(Unknown Source)
at com.lowagie.text.pdf.BaseFont.enumerateTTCNames(Unknown Source)
at com.lowagie.text.FontFactoryImp.register(Unknown Source)
at com.lowagie.text.FontFactory.register(Unknown Source)
at com.lowagie.text.FontFactory.register(Unknown Source)
at com.mycompany.myproject.PDFGenerationTest.testGeneratePDF(PDFGenerationTest.java:37)
at ...
如你所见,上面没有关于在com.lowagie.text
包下的每个错误抛出的具体代码行号信息。此外,我尝试在IntelliJ中调试代码,但调试器不会停在库代码处(只会停在我的项目代码处)。
你知道为什么会出现这种情况吗?
英文:
I have a Java project where I'm using iText 2.1.7 (a pretty old version, I know, but it's a legacy project) to some PDF files. I've created a test like follows in order to tune and debug some font-related issues:
@Test
public void testGeneratePDF() throws FileNotFoundException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream("test.pdf"));
document.open();
String fontPath = this.getClass().getClassLoader().getResource("NotoSansCJK.ttc").getPath();
FontFactory.register(fontPath);
Set<String> fonts = new TreeSet<String>(FontFactory.getRegisteredFonts());
for (String fontname : fonts) {
showFontInfo(document, fontname);
}
document.close();
}
And when I run the test, I get the following error trace:
> ExceptionConverter: com.lowagie.text.DocumentException: /Users/jdebenitocalzada/dev/myproject/target/test-classes/NotoSansCJK.ttc is not a valid TTF file.
at com.lowagie.text.pdf.EnumerateTTC.findNames(Unknown Source)
at com.lowagie.text.pdf.EnumerateTTC.<init>(Unknown Source)
at com.lowagie.text.pdf.BaseFont.enumerateTTCNames(Unknown Source)
at com.lowagie.text.FontFactoryImp.register(Unknown Source)
at com.lowagie.text.FontFactory.register(Unknown Source)
at com.lowagie.text.FontFactory.register(Unknown Source)
at com.mycompany.myproject.PDFGenerationTest.testGeneratePDF(PDFGenerationTest.java:37)
at ...
As you can see above, there's no information about line numbers where each error was thrown under com.lowagie.text package classes. In addition, I've tried to debug the code in IntelliJ but the debugger doesn't stop at the library code (it does at my own project code).
Any idea why this happens?
专注分享java语言的经验与见解,让所有开发者获益!
评论