Skip to content

Commit 9b277ec

Browse files
Review checked exceptions softening in layout module
Autoported commit. Original commit hash: [8d67c4213] Manual files: layout/findbugs-filter.xml layout/src/main/java/com/itextpdf/layout/hyphenation/PatternParser.java
1 parent 56e5b43 commit 9b277ec

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

itext/itext.layout/itext/layout/font/FontProvider.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ public virtual PdfFont GetPdfFont(FontInfo fontInfo, FontSet tempFonts) {
412412
pdfFont = PdfFontFactory.CreateFont(fontProgram, encoding, GetDefaultEmbeddingFlag());
413413
}
414414
catch (System.IO.IOException e) {
415+
// Converting checked exceptions to unchecked RuntimeException (java-specific comment).
416+
//
417+
// FontProvider is usually used in highlevel API, which requests fonts in deep underlying logic.
418+
// IOException would mean that font is chosen and it is supposed to exist, however it cannot be read.
419+
// Using fallbacks in such situations would make FontProvider less intuitive.
420+
//
421+
// Even though softening of checked exceptions can be handled at higher levels in order to let
422+
// the caller of this method know that font creation failed, we prefer to avoid bloating highlevel API
423+
// and avoid making higher level code depend on low-level code because of the exceptions handling.
415424
throw new PdfException(PdfException.IoExceptionWhileCreatingFont, e);
416425
}
417426
pdfFonts.Put(fontInfo, pdfFont);

itext/itext.layout/itext/layout/renderer/TypographyUtils.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ private static Object CallMethod(String className, String methodName, Object tar
289289
, e.Message));
290290
}
291291
catch (Exception e) {
292+
// Converting checked exceptions to unchecked RuntimeException (java-specific comment).
293+
//
294+
// If typography utils throws an exception at this point, we consider it as unrecoverable situation for
295+
// its callers (layouting methods). Presence of typography module in class path is checked before.
296+
// It's might be more suitable to wrap checked exceptions at a bit higher level, but we do it here for
297+
// the sake of convenience.
298+
//
299+
// The RuntimeException exception is used instead of, for example, PdfException, because failure here is
300+
// unexpected and is not connected to PDF documents processing.
292301
throw new Exception(e.ToString(), e);
293302
}
294303
return null;
@@ -306,6 +315,15 @@ private static Object CallConstructor(String className, Type[] parameterTypes, p
306315
logger.Warn(MessageFormatUtil.Format("Cannot find class {0}", className));
307316
}
308317
catch (Exception exc) {
318+
// Converting checked exceptions to unchecked RuntimeException (java-specific comment).
319+
//
320+
// If typography utils throws an exception at this point, we consider it as unrecoverable situation for
321+
// its callers (layouting methods). Presence of typography module in class path is checked before.
322+
// It's might be more suitable to wrap checked exceptions at a bit higher level, but we do it here for
323+
// the sake of convenience.
324+
//
325+
// The RuntimeException exception is used instead of, for example, PdfException, because failure here is
326+
// unexpected and is not connected to PDF documents processing.
309327
throw new Exception(exc.ToString(), exc);
310328
}
311329
return null;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5fc41659adec32a84946e832bd2ac17e9defb31c
1+
8d67c42138b14653256da2f84970f355bc5c20a1

0 commit comments

Comments
 (0)