Hi devs,
Our File encoding rules say:
- Java source files must contain only ASCII chars (Unicode escapes in strings, XML entities in javadoc).
- Translation files must contain only ASCII chars and Unicode escapes.
- Wiki document sources must be stored in UTF-8.
- Other XML files should specify their encoding in the
<?xml>header, UTF-8 as often as possible. - All other textual resources must be UTF-8, minimizing the use of non-ASCII chars.
None of this is enforced by the build today, so I’ve audited the master branches of commons, rendering and platform (as of 2026-10-06; ~9,600 Java files, ~640 properties files, ~3,200 XML files and ~3,900 other text files scanned). Here’s the status.
Status
Rule 1 — Java sources must be ASCII-only:
74 files
- Main code: 22 files (1 rendering, 21 platform). Almost all of them are comments containing typographic characters (
’U+2019 instead of',—em dash, non-breaking spaces) that most likely come from copy/paste or from IDE/LLM-generated text. Only 3 are in string literals:EventClassDocumentInitializer("Listen to …"),ObjectDiff(" ⇨ ") andHTML5Validator(“h3”, matching a message from the validator). - Test code: 52 files (6 commons, 3 rendering, 43 platform). These are almost all intentional test data in string literals: accented letters, Cyrillic, Greek, etc. used to test escaping, slugs, parsers, etc. (e.g.
CommonWikiParserTest,DefaultHTMLCleanerTest,ReplaceCharacterEntityNameValidationTest). - All 74 files are valid UTF-8, so nothing is actually broken: we build with
project.build.sourceEncoding=UTF-8and, since Java 18 (JEP 400), UTF-8 is also the JVM default charset. The original risk this rule protected against (a platform-dependent default charset garbling the sources) is mostly gone.
Main Java files with non-ASCII chars
- rendering:
AgregatingWemListener(a decorative comment line made ofè) - platform:
WikiBaseObjectComponentBuilder,CachedLESSCompiler,DefaultSolrIndexer,NotificationFilterPreference,NotificationFilter(typopĥase),SystemUserNotificationFilter,OwnEventFilter,EventUserFilter,AbstractMinorEventNotificationFilter,DefaultNotificationRSSManager,DefaultSecurityCache,EventClassDocumentInitializer,DefaultModelBridge,LiveNotificationEmailListener,LiveNotificationEmailManager,ExpressionNodeToHQLConverter,SimpleDocumentCache,ExportURLFactory,ObjectDiff,Document,HTML5Validator - Also 3 AspectJ files in legacy modules (
AbstractMacroAspect.aj,DeleteActionCompatibilityAspect.aj,XWikiActionCompatibilityAspect.aj), with a’in comments.
Rule 2 — Translation files must be ASCII + \uXXXX escapes:
54 files, getting worse
- 54
ApplicationResources_*.propertiesfiles (2 rendering, 52 platform) contain 411 lines with raw non-ASCII chars, and all of them are ISO-8859-1 encoded (none is valid UTF-8). 56 of those lines are only### Missing:comments. - Root cause: these lines come from Weblate commits (“Translated using Weblate (French/German/…)”), starting around December 2025. Weblate writes chars that exist in Latin-1 raw and still escapes the others, e.g. the
_ukfiles mix a raw«with escaped Cyrillic chars. So it looks like the Weblate file format setting is “Java Properties (ISO-8859-1)” rather than one that escapes everything. @surli could you confirm this and tell us whether something changed in the Weblate configuration around that time? - It works at runtime because we load translations with
Properties.load(InputStream), which reads ISO-8859-1. However, it’s fragile: our sources are declared as UTF-8, so an IDE/editor opening one of these files shows garbage and can silently corrupt it when saving, and tools likegit log -S/ grep with UTF-8 search terms don’t match.
Rule 3 — Wiki documents in UTF-8: 
All XAR pages under src/main/resources are UTF-8 and declare it. The only exceptions are test fixtures: 17 pages in the XAR tool integration tests (commons) declaring ISO-8859-1 (with ASCII-only content) and 6 legacy-format test documents in the packager plugin ITs encoded in ISO-8859-1.
Rule 4 — Other XML files declare their encoding:
minor
- Main: 9 XML files without an
<?xml>declaration (5 assembly descriptors, 2pom.xmlinxwiki-platform-security-requiredrights,eclipse-m2e-lifecycle.xmlandcodestyle-idea.xmlin verification-resources) and 2 SVGs without anencodingattribute. - Test: 70 files (missing declaration/encoding, 2 declaring ISO-8859-1).
- None of them contains non-ASCII chars, so it’s harmless. The rules page already says “Currently, only the XML rules are broken” and that’s still true.
Rule 5 — Other textual resources in UTF-8, minimizing non-ASCII:
(mostly)
- All files are valid UTF-8, except the 6 legacy test documents mentioned above. One file has a UTF-8 BOM (Solr’s
stopwords_sk.txt, third party). - Non-ASCII in main files is either legitimate (Solr stopwords/language files, third-party font READMEs/licenses,
×/»/—in JS/TS/Vue UI code) or accidental: invisible non-breaking spaces (U+00A0) in some Velocity templates (macros.vm,importinline.vm,imported.vm,flavor/macros.vm,xwiki.cfg.vm) and LESS files (drawer.less,livetable.less).
Proposal
I’d like to confirm we still want these rules and, if so, to enforce the important ones with Checkstyle so that we stop drifting:
-
Java main code: keep ASCII-only and enforce it. Fix the 22 files (mostly
’→'in comments) and add a Checkstyle rule. -
Java test code: to be decided. What triggered this audit is this new test in PR #6563, which uses chars such as
©€½and emojis (😀🏁🍕) directly in Java strings. Two options:- A. Keep the rule for tests too (enforce it in
checkstyle-test.xmlas well) and convert the 52 test files to\uXXXXescapes, optionally with a comment showing the actual char. Pro: one simple rule everywhere, no surprise when moving code from tests to main. Con: tests become harder to read, especially for emojis, which need surrogate pairs (e.g.😀, U+1F600, must be written as two escapes, for the surrogatesD83DandDE00). - B. Relax the rule for tests: test Java sources may contain non-ASCII chars but must be UTF-8. Pro: readable test data. Con: two rules to remember. The encoding risk itself is low nowadays (UTF-8 sources + JEP 400).
I’m personally fine converting tests to ASCII-only content (option A), but I’d like to hear your opinions.
- A. Keep the rule for tests too (enforce it in
-
Translation files: keep ASCII +
\uXXXXescapes and enforce it. This requires first confirming and changing the Weblate file format setting so that it escapes all non-ASCII chars (otherwise the build will fail on Weblate commits), then re-escaping the 54 files, then adding the Checkstyle rule. The alternative would be to switch translation files to UTF-8, but that means changing how we load them (Properties.load(Reader)) with backward-compatibility impacts on extensions shipping ISO-8859-1 translation files, so I don’t think it’s worth it. -
XML and other resources: no enforcement. Fix the few main XML files missing the declaration and the invisible non-breaking spaces opportunistically.
For 1 and 3, a single Checkstyle module in checkstyle.xml would do it, since the Maven Checkstyle plugin already checks src/main/java and src/main/resources/**/*.properties by default. Test sources are checked by a separate execution using checkstyle-test.xml, so for option 2A we’d add the same module there too (with fileExtensions set to java):
<module name="RegexpSingleline">
<property name="format" value="[^\x00-\x7F]"/>
<property name="fileExtensions" value="java, properties"/>
<property name="message"
value="Only ASCII characters are allowed. Use \uXXXX escapes in strings and properties, and HTML entities in javadoc."/>
</module>
Here’s my +1 for 1, 3 and 4. For 2, I’m fine with A but open to B.
WDYT?
Thanks