Skip to content

Commit 417675c

Browse files
Peter EliassonJohan Redestig
authored andcommitted
Improved error handling when font loading fails.
Without this patch, an application could trigger a platform crash by calling: Typeface typeface = Typeface.createFromFile(""); boolean isbold = typeface.isBold(); The crash occurs since the Skia error that occurs when font loading fails is not propagated. With this patch, the Typeface constructor throws an IllegalStateException when Skia fails to load the font (i.e. when the native instance is null). Change-Id: I1002b37b7b32840cb7eeef6819d2982cb18c9003
1 parent 5a870fe commit 417675c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

graphics/java/android/graphics/Typeface.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public static Typeface createFromFile(String path) {
143143

144144
// don't allow clients to call this directly
145145
private Typeface(int ni) {
146+
if (ni == 0) {
147+
throw new IllegalStateException();
148+
}
146149
native_instance = ni;
147150
}
148151

0 commit comments

Comments
 (0)