1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 19:42:17 +02:00

fixed possible NPE

This commit is contained in:
Nikolay Pultsin 2014-04-21 14:13:26 +01:00
parent cce8974b24
commit 17e18c184b

View file

@ -48,10 +48,13 @@ abstract class ZLTextViewBase extends ZLView {
} }
private ZLTextMetrics metrics() { private ZLTextMetrics metrics() {
if (myMetrics == null) { // this local variable is used to guarantee null will not
// be returned from this method enen in multi-thread environment
ZLTextMetrics m = myMetrics;
if (m == null) {
final ZLTextStyleCollection collection = getTextStyleCollection(); final ZLTextStyleCollection collection = getTextStyleCollection();
final ZLTextBaseStyle base = collection.getBaseStyle(); final ZLTextBaseStyle base = collection.getBaseStyle();
myMetrics = new ZLTextMetrics( m = new ZLTextMetrics(
ZLibrary.Instance().getDisplayDPI(), ZLibrary.Instance().getDisplayDPI(),
collection.getDefaultFontSize(), collection.getDefaultFontSize(),
base.getFontSize(), base.getFontSize(),
@ -62,8 +65,9 @@ abstract class ZLTextViewBase extends ZLView {
// TODO: screen area height // TODO: screen area height
100 100
); );
myMetrics = m;
} }
return myMetrics; return m;
} }
final int getWordHeight() { final int getWordHeight() {