Status of File encoding rules + proposal to enforce them with Checkstyle

Hi devs,

Our File encoding rules say:

  1. Java source files must contain only ASCII chars (Unicode escapes in strings, XML entities in javadoc).
  2. Translation files must contain only ASCII chars and Unicode escapes.
  3. Wiki document sources must be stored in UTF-8.
  4. Other XML files should specify their encoding in the <?xml> header, UTF-8 as often as possible.
  5. 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: :cross_mark: 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 (" ⇨ ") and HTML5Validator (“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-8 and, 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 (typo pĥ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: :cross_mark: 54 files, getting worse

  • 54 ApplicationResources_*.properties files (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 _uk files 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 like git log -S / grep with UTF-8 search terms don’t match.

Rule 3 — Wiki documents in UTF-8: :white_check_mark:

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: :warning: minor

  • Main: 9 XML files without an <?xml> declaration (5 assembly descriptors, 2 pom.xml in xwiki-platform-security-requiredrights, eclipse-m2e-lifecycle.xml and codestyle-idea.xml in verification-resources) and 2 SVGs without an encoding attribute.
  • 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: :white_check_mark: (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:

  1. Java main code: keep ASCII-only and enforce it. Fix the 22 files (mostly ’ → ' in comments) and add a Checkstyle rule.

  2. 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.xml as well) and convert the 52 test files to \uXXXX escapes, 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 surrogates D83D and DE00).
    • 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.

  3. Translation files: keep ASCII + \uXXXX escapes 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.

  4. 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

I think this rule does not make much sense anymore, since that’s not the rule we are currently following (enforced at Weblate level): translation file should use the encoding of the type of files they are using (in the case of properties file, ISO-8859-1).

I think that we meant properties files when we said “translation files”. Especially since we also have a rule for “Wiki document sources must be stored in UTF-8.”.

+1 from me to clarify the text/rule.

Well note that this is only since Java 18. So only the XWiki 18.x source (moved to Java 21) is protected officially. I guess we should set <encoding> explicitly in the compiler configuration to avoid any confusion.

Sure but my point was that this rule does not make sense for properties files since that’s not the rule we currently follow, I think we even discussed it (the switch to ISO-8859-1). @surli probably remember better than me.

I’m not a fan of a mixed rule. I feel like we should move to UTF8 since that’s the current Java specification (and just make sure the compiler plugin is properly configured in the 17.10.x/16.10.x branches).

I don’t see much reason to force ASCII since we parse those files as ISO-8859-1 and we already discussed the move to ISO-8859-1 after a Weblate upgrade (I guess we forgot to update that rule).

+1

Thanks @tmortagne for the feedback. Since the proposal has changed a lot (Java sources moving to UTF-8, properties files staying ISO-8859-1, new Checkstyle rules and a rewording of the dev practices page), I’ve opened a new thread to have a clean vote: Proposal: Move Java sources to UTF-8 and update the File encoding rules

Let’s continue there.