From ecdd15064e3aaaa7413a77c5c4d3a036e6101daa Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Thu, 28 May 2026 12:12:32 +0300 Subject: [PATCH] Restore JavaSEPort.instance in JavaSEPortFontMappingTest JavaSEPortFontMappingTest constructs `new JavaSEPort()` inside two of its tests; the JavaSEPort constructor unconditionally assigns `instance = this`, so the throwaway port leaks into the global static. If CodenameOneExtensionTest then runs in the same JVM after Display has already been initialized (e.g. by PaintScopeTest), the extension's @LargerText / @Orientation handling mutates the wrong port via JavaSEPort.instance while Display.impl still references the original, and the assertions read stale defaults. The bug is order-dependent: master's recent CI runs happened to pick a test order where CodenameOneExtensionTest ran first, so the leak was masked; PR runs that interleaved PaintScopeTest, FontMappingTest, and CodenameOneExtensionTest in the failing order surfaced it as two test failures ("expected: <1.6> but was: <1.0>", "expected: but was: "). Capture JavaSEPort.instance in @BeforeEach and restore it in @AfterEach so the test no longer leaks across test classes. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../javase/JavaSEPortFontMappingTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/maven/javase/src/test/java/com/codename1/impl/javase/JavaSEPortFontMappingTest.java b/maven/javase/src/test/java/com/codename1/impl/javase/JavaSEPortFontMappingTest.java index e865aa191b..c7528ca498 100644 --- a/maven/javase/src/test/java/com/codename1/impl/javase/JavaSEPortFontMappingTest.java +++ b/maven/javase/src/test/java/com/codename1/impl/javase/JavaSEPortFontMappingTest.java @@ -5,14 +5,28 @@ import java.lang.reflect.Field; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; public class JavaSEPortFontMappingTest { - + private Boolean originalIsIOS; + private JavaSEPort originalInstance; + private boolean instanceCaptured; + + @BeforeEach + public void captureInstance() { + // new JavaSEPort() inside the loadTrueTypeFont tests overwrites the + // global JavaSEPort.instance via the port's constructor. Other test + // classes (CodenameOneExtensionTest) reach back through that static + // to drive the live Display, so leaking the throwaway port across + // test classes causes order-dependent failures. + originalInstance = JavaSEPort.instance; + instanceCaptured = true; + } @AfterEach public void tearDown() throws Exception { @@ -20,6 +34,9 @@ public void tearDown() throws Exception { if (originalIsIOS != null) { setIsIOS(originalIsIOS.booleanValue()); } + if (instanceCaptured) { + JavaSEPort.instance = originalInstance; + } } private void setIsIOS(boolean value) throws Exception {