Commit 25dbe3e
Fix initializr localization bundle path (NPE in MyAppName.init) (#4852)
* Fix initializr localization bundles + harden simulator designer lookup
The initializr's "include localization bundles" option generated bundles
under common/src/main/resources/messages*.properties, but the CN1 maven
plugin's CSS compiler scans common/src/main/l10n (or i18n) for bundles to
bake into theme.res. The result: Resources.getGlobalResources().getL10N(
"messages", lang) hit a missing resource id at simulator startup and
threw NPE in MyAppName.init -- the project couldn't run.
- GeneratorModel.addLocalizationEntries: write to src/main/l10n so the
bundles actually end up inside theme.res.
- Bootstrap (Java + Kotlin) injected into the starter class is now
null-safe and falls back to the default locale when the device
language has no specific bundle.
- Resources.getL10N / listL10NLocales / l10NLocaleSet now return null
instead of NPE-ing when the bundle id is absent. Defensive change at
the framework level so any project shipping mismatched bundles
degrades gracefully.
- New tests/core/.../ResourcesL10NTest covers the framework null-safety.
- GeneratorModelMatrixTest now asserts bundles land under l10n and are
NOT under src/main/resources (catches the regression at unit-test
time).
- GeneratorModelIntegrationBuildTest now opens common/target/classes/
theme.res after mvn compile and verifies "messages" L10N data is
present for both the default ("") and Hebrew ("he") locales -- the
end-to-end signal the previous tests missed.
While here, harden the simulator's CSS compiler invocation against
stale ~/.codenameone/designer_1.jar:
- New MavenUtils.findDesignerJarInM2 derives the running CN1 version
from the codenameone-core jar's m2 path and resolves the matching
codenameone-designer-<version>-jar-with-dependencies.jar. Any plugin
invocation has already pulled this into m2 as a plugin dependency.
- CSSWatcher and ComponentTreeInspector now prefer codename1.designer.jar
-> m2 designer -> ~/.codenameone fallback (with a clear warning when
the legacy fallback is hit). The build-time CSS goal already used
getDesignerJar() so this only affects the simulator runtime / live
CSS reload paths.
- CompileCSSMojo now invokes the forked CSS compiler with INFO log
level instead of DEBUG so subprocess stack traces are visible without
re-running with -X. This won't fix issue #4850 but makes the next
similar report actionable.
- The four initializr pom templates replace skipexisting="true" with
usetimestamp="true" on the UpdateCodenameOne.jar download so future
installs refresh the updater jar instead of pinning forever to the
first copy.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* CompileCSSMojo: route INFO log level through createJava() override
The previous patch raised the CSS subprocess log level by passing it
explicitly at the call site (createJava(LEVEL_INFO)), which bypasses
CompileCSSMojoTest's TestCompileCSSMojo.createJava() override -- the
test substitutes a RecordingJava there to capture the command line
without forking. The override was no longer hit, so the test fell
through to a real fork against a stub designer.jar and four tests
errored out with "Invalid or corrupt jarfile".
Move the INFO log level into a createJava() override on CompileCSSMojo
itself. The call site stays at createJava(), so the test override
continues to win, and production still gets INFO so subprocess stack
traces remain visible without -X.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Fix CSS compiler StringIndexOutOfBoundsException for initializr projects
The user shared the missing stack trace from issue #4850:
at java.base/java.lang.String.substring(String.java:2899)
at com.codename1.ui.plaf.UIManager.parseTextFieldInputMode(UIManager.java:2434)
at com.codename1.ui.plaf.UIManager.setBundle(UIManager.java:2419)
at com.codename1.impl.javase.JavaSEPort.enableAutoLocalizationBundle(...)
at com.codename1.impl.javase.JavaSEPort.init(JavaSEPort.java:5598)
at com.codename1.impl.CodenameOneImplementation.initImpl(...)
at com.codename1.ui.Display.init(Display.java:351)
at com.codename1.designer.css.CN1CSSCLI.main(CN1CSSCLI.java:713)
This is not a path-related bug -- every initializr-generated project hits
it at css-goal time. Three pieces interact:
1. JavaSEPort.findLocalizationDirectory auto-creates src/main/l10n if it
is missing, and enableAutoLocalizationBundle installs an
AutoLocalizationBundle for it.
2. AutoLocalizationBundle.get echoes any missing key back as its own
value -- the simulator's "wormhole" so devs can spot untranslated
strings.
3. UIManager.setBundle queries "@im" on every bundle install. With the
echo behavior, "@im" -> "@im", which is then tokenized to ["@im"],
"@im-@im" is queried (which echoes "@im-@im"), and
parseTextFieldInputMode crashes on substring(0, indexOf('=')) because
that token has no '=' (range [0, -1) of length 7).
The CSS compiler subprocess inherits all of this because CN1CSSCLI.main
calls Display.init -> JavaSEPort.init -> enableAutoLocalizationBundle.
Fixes:
- AutoLocalizationBundle.get returns null for keys starting with '@'.
Meta-keys (@rtl, @im, @im-<name>) are configuration entries that
callers distinguish from "missing" by checking for null. Echoing the
key back is semantically wrong AND broke setBundle. Real meta-key
values that exist in the underlying file (e.g. @rtl=true in a Hebrew
bundle) are still returned -- only fabrication is suppressed.
- UIManager.parseTextFieldInputMode skips tokens without '=' and skips
entries whose key isn't a valid integer. Defensive belt-and-suspenders
so any bundle with malformed input-mode entries degrades gracefully
instead of failing the whole bundle install.
- New UIManagerSetBundleTest exercises setBundle against an echo-bundle
(matches pre-fix AutoLocalizationBundle behavior) and against directly
malformed @im/@im-x entries.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Revert parseTextFieldInputMode fail-safe; keep AutoLocalizationBundle fix
Per review: silently skipping malformed `@im` tokens hides legitimate
bugs in user-supplied bundles. Real malformed input should fail loudly,
not be swallowed.
The actual root cause -- AutoLocalizationBundle fabricating values for
@-prefixed meta-keys -- stays fixed. That's the surgical change: the
auto-localize wormhole was returning fake values for keys that callers
explicitly use null/non-null to gate features (@im, @rtl, @im-<name>),
which is semantically wrong and broke setBundle.
Moves the regression coverage from the no-op stub in core to the
existing AutoLocalizationBundleTest in the JavaSE port (where the bundle
class actually lives), asserting:
- @-prefixed meta-keys are NOT auto-fabricated
- @-prefixed meta-keys that exist in the underlying file ARE returned
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Initializr: ship Bundle.properties stub with @im= to dodge simulator wormhole
Workaround for the AutoLocalizationBundle @im fabrication crash in
shipped Codename One <= 7.0.236. The proper fix lives in JavaSEPort
(don't fabricate values for `@`-prefixed meta-keys) and is on this
branch, but it requires a new framework release. Until then, every
initializr-generated project crashes at css-goal time inside the CSS
compiler subprocess (CN1CSSCLI -> Display.init -> JavaSEPort.init ->
enableAutoLocalizationBundle -> UIManager.setBundle ->
parseTextFieldInputMode on substring(0, -1) for "@im-@im").
Ship `common/src/main/l10n/Bundle.properties` with a single `@im=`
entry on every generated project. Two reasons it works:
1. JavaSEPort.findDefaultLocalizationBundleFile prefers Bundle.properties
over any other file in src/main/l10n, so the AutoLocalizationBundle
loads our stub as its base.
2. With `@im=""` already in the bundle's underlying Hashtable,
AutoLocalizationBundle.get("@im") returns "" instead of fabricating
"@im". setBundle sees length 0 and skips the input-mode block, so
parseTextFieldInputMode is never called.
The stub is unconditional (added to every project, with or without
localization bundles enabled) because the bug fires regardless --
enableAutoLocalizationBundle auto-creates src/main/l10n in the CSS
compiler subprocess even on projects that didn't request localization.
The matrix test asserts the stub is present on every generated project
combination so this workaround can't silently regress.
Once the AutoLocalizationBundle fix lands in a release and the
initializr is bumped past it, this stub can be removed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 72e4758 commit 25dbe3e
15 files changed
Lines changed: 313 additions & 34 deletions
File tree
- CodenameOne/src/com/codename1/ui/util
- Ports/JavaSE/src/com/codename1/impl/javase
- util
- maven/codenameone-maven-plugin/src/main/java/com/codename1/maven
- scripts/initializr/common/src
- main
- java/com/codename1/initializr/model
- resources
- test/java/com/codename1/initializr/model
- tests/core
- src/com/codename1/ui/util
- test/com/codename1/impl/javase
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
929 | 929 | | |
930 | 930 | | |
931 | 931 | | |
932 | | - | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
933 | 937 | | |
934 | 938 | | |
935 | 939 | | |
| |||
942 | 946 | | |
943 | 947 | | |
944 | 948 | | |
945 | | - | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
946 | 954 | | |
947 | 955 | | |
948 | 956 | | |
| |||
955 | 963 | | |
956 | 964 | | |
957 | 965 | | |
958 | | - | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
959 | 971 | | |
960 | 972 | | |
961 | 973 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
275 | 291 | | |
276 | 292 | | |
277 | 293 | | |
| |||
Lines changed: 24 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
580 | 580 | | |
581 | 581 | | |
582 | 582 | | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
587 | 588 | | |
588 | | - | |
589 | | - | |
590 | | - | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
591 | 594 | | |
592 | | - | |
593 | | - | |
594 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
595 | 609 | | |
596 | 610 | | |
597 | 611 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14295 | 14295 | | |
14296 | 14296 | | |
14297 | 14297 | | |
| 14298 | + | |
| 14299 | + | |
| 14300 | + | |
| 14301 | + | |
| 14302 | + | |
| 14303 | + | |
| 14304 | + | |
| 14305 | + | |
| 14306 | + | |
14298 | 14307 | | |
14299 | 14308 | | |
14300 | 14309 | | |
| |||
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
66 | 111 | | |
67 | 112 | | |
68 | 113 | | |
| |||
Lines changed: 21 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
46 | 62 | | |
47 | 63 | | |
48 | 64 | | |
| |||
232 | 248 | | |
233 | 249 | | |
234 | 250 | | |
235 | | - | |
| 251 | + | |
236 | 252 | | |
237 | 253 | | |
238 | 254 | | |
239 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
240 | 259 | | |
241 | 260 | | |
242 | 261 | | |
| |||
Lines changed: 60 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
105 | 143 | | |
106 | 144 | | |
107 | 145 | | |
108 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
109 | 151 | | |
110 | | - | |
| 152 | + | |
111 | 153 | | |
112 | 154 | | |
113 | 155 | | |
| |||
117 | 159 | | |
118 | 160 | | |
119 | 161 | | |
120 | | - | |
| 162 | + | |
121 | 163 | | |
122 | 164 | | |
123 | 165 | | |
| |||
356 | 398 | | |
357 | 399 | | |
358 | 400 | | |
359 | | - | |
360 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
361 | 409 | | |
362 | 410 | | |
363 | 411 | | |
| |||
374 | 422 | | |
375 | 423 | | |
376 | 424 | | |
377 | | - | |
378 | | - | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
379 | 433 | | |
380 | 434 | | |
381 | 435 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | | - | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
63 | | - | |
| 67 | + | |
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
| |||
0 commit comments