From ca154ac967599ba72d5d9dd98ae68db5d21d99c5 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Tue, 14 Nov 2017 13:59:31 +0100 Subject: jni: Clarify initialization order in Context. Previously the initialization order of init() and the field inited was not obvious. Move the static block as far up as possible but make sure that inited is initialized before that. Also add a comment explaining why. --- platform/java/src/com/artifex/mupdf/fitz/Context.java | 9 +++++++-- .../src/com/artifex/mupdf/fitz/android/AndroidDrawDevice.java | 8 ++++---- .../java/src/com/artifex/mupdf/fitz/android/AndroidImage.java | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'platform/java/src') diff --git a/platform/java/src/com/artifex/mupdf/fitz/Context.java b/platform/java/src/com/artifex/mupdf/fitz/Context.java index 5ad384db..681375aa 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/Context.java +++ b/platform/java/src/com/artifex/mupdf/fitz/Context.java @@ -8,7 +8,14 @@ package com.artifex.mupdf.fitz; // function. public class Context { + // Make sure to initialize inited before calling + // init() from the static block below. private static boolean inited = false; + + static { + init(); + } + private static native int initNative(); public static native int gprfSupportedNative(); @@ -29,8 +36,6 @@ public class Context } } - static { init(); } - // FIXME: We should support the store size being changed dynamically. // This requires changes within the MuPDF core. //public native static void setStoreSize(long newSize); diff --git a/platform/java/src/com/artifex/mupdf/fitz/android/AndroidDrawDevice.java b/platform/java/src/com/artifex/mupdf/fitz/android/AndroidDrawDevice.java index 38bb0447..263d8ecf 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/android/AndroidDrawDevice.java +++ b/platform/java/src/com/artifex/mupdf/fitz/android/AndroidDrawDevice.java @@ -2,12 +2,12 @@ package com.artifex.mupdf.fitz.android; import android.graphics.Bitmap; +import com.artifex.mupdf.fitz.Context; +import com.artifex.mupdf.fitz.Matrix; import com.artifex.mupdf.fitz.NativeDevice; -import com.artifex.mupdf.fitz.RectI; -import com.artifex.mupdf.fitz.Rect; - import com.artifex.mupdf.fitz.Page; -import com.artifex.mupdf.fitz.Matrix; +import com.artifex.mupdf.fitz.Rect; +import com.artifex.mupdf.fitz.RectI; public final class AndroidDrawDevice extends NativeDevice { diff --git a/platform/java/src/com/artifex/mupdf/fitz/android/AndroidImage.java b/platform/java/src/com/artifex/mupdf/fitz/android/AndroidImage.java index 3a6ebb99..505b4efb 100644 --- a/platform/java/src/com/artifex/mupdf/fitz/android/AndroidImage.java +++ b/platform/java/src/com/artifex/mupdf/fitz/android/AndroidImage.java @@ -2,6 +2,7 @@ package com.artifex.mupdf.fitz.android; import android.graphics.Bitmap; +import com.artifex.mupdf.fitz.Context; import com.artifex.mupdf.fitz.Image; public final class AndroidImage extends Image -- cgit v1.2.3