From 3d0dee98befd6fb6de1910b878f7359b44a92167 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Thu, 9 Feb 2017 14:53:26 +0000 Subject: [PATCH] Fix first-time instantiation via reflection. In 7fc035f, a general fix to instantiation via reflection was made and a test case added. The test case fails due to a separate issue, solved in this commit, which affects only the first instantiation via reflection. --- platform/src/main/java/org/teavm/platform/Platform.java | 7 ++++++- .../java/org/teavm/platform/plugin/PlatformGenerator.java | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/platform/src/main/java/org/teavm/platform/Platform.java b/platform/src/main/java/org/teavm/platform/Platform.java index 6f6b02d1e..5ce1184b5 100644 --- a/platform/src/main/java/org/teavm/platform/Platform.java +++ b/platform/src/main/java/org/teavm/platform/Platform.java @@ -33,6 +33,8 @@ public final class Platform { private Platform() { } + private static boolean newInstancePrepared; + @InjectedBy(PlatformGenerator.class) public static native PlatformObject getPlatformObject(Object obj); @@ -85,7 +87,10 @@ public final class Platform { public static native int nextObjectId(); public static T newInstance(PlatformClass cls) { - prepareNewInstance(); + if (!newInstancePrepared) { + prepareNewInstance(); + newInstancePrepared = true; + } return newInstanceImpl(cls); } diff --git a/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java b/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java index bd9172362..4537f2ea7 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java +++ b/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java @@ -117,9 +117,6 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin .appendMethodBody(method.getReference()).append(";").softNewLine(); } } - writer.appendMethodBody(Platform.class, "newInstance", PlatformClass.class, Object.class).ws().append('=').ws() - .appendMethodBody(Platform.class, "newInstanceImpl", PlatformClass.class, Object.class) - .append(";").softNewLine(); } private void generateNewInstance(GeneratorContext context, SourceWriter writer) throws IOException {