Skip to content

Commit

Permalink
Improve FONT_EMBEDDING_ISSUE exception handling
Browse files Browse the repository at this point in the history
DEVSIX-5147
  • Loading branch information
nikitakovaliov92 authored and ars18wrw committed Jul 26, 2021
1 parent f85af9e commit 97afe9f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kernel/src/main/java/com/itextpdf/kernel/font/PdfFont.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ protected static String updateSubsetPrefix(String fontName, boolean isSubset, bo
* @throws PdfException Method will throw exception if {@code fontStreamBytes} is {@code null}.
*/
protected PdfStream getPdfFontStream(byte[] fontStreamBytes, int[] fontStreamLengths) {
if (fontStreamBytes == null) {
if (fontStreamBytes == null || fontStreamLengths == null) {
throw new PdfException(KernelExceptionMessageConstant.FONT_EMBEDDING_ISSUE);
}
PdfStream fontStream = new PdfStream(fontStreamBytes);
Expand Down
18 changes: 18 additions & 0 deletions kernel/src/test/java/com/itextpdf/kernel/font/PdfFontUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,22 @@ public void cannotGetFontStreamForNullBytesTest() throws IOException {
PdfFont pdfFont = PdfFontFactory.createFont();
pdfFont.getPdfFontStream(null, new int[] {1});
}

@Test
public void cannotGetFontStreamForNullLengthsTest() throws IOException {
junitExpectedException.expect(PdfException.class);
junitExpectedException.expectMessage(KernelExceptionMessageConstant.FONT_EMBEDDING_ISSUE);

PdfFont pdfFont = PdfFontFactory.createFont();
pdfFont.getPdfFontStream(new byte[] {1}, null);
}

@Test
public void cannotGetFontStreamForNullBytesAndLengthsTest() throws IOException {
junitExpectedException.expect(PdfException.class);
junitExpectedException.expectMessage(KernelExceptionMessageConstant.FONT_EMBEDDING_ISSUE);

PdfFont pdfFont = PdfFontFactory.createFont();
pdfFont.getPdfFontStream(null, null);
}
}

0 comments on commit 97afe9f

Please sign in to comment.