From c5b0a04b16ccecf16d7d2a571c67c5dde0b24b35 Mon Sep 17 00:00:00 2001 From: Thomas Segismont Date: Mon, 30 Nov 2026 18:49:39 +0100 Subject: [PATCH] Normalize line endings with a precompiled pattern The pattern matches CRLF, CR and LF atomically, which makes the conversion idempotent: content that already contains the local line endings, for example when a generator uses println or embeds the system line separator, is normalized instead of being corrupted with doubled carriage returns. The no-op fast path for LF systems is removed: it was only correct under the assumption that generators never emit the platform line separator, which cannot be guaranteed for the render() SPI. Signed-off-by: Thomas Segismont --- .../io/vertx/codegen/processor/Processor.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/Processor.java b/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/Processor.java index 28a90d77..3b94a1af 100644 --- a/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/Processor.java +++ b/vertx-codegen-processor/src/main/java/io/vertx/codegen/processor/Processor.java @@ -37,11 +37,10 @@ public class Processor extends AbstractProcessor { private static final String JSON_MAPPERS_PROPERTIES_PATH = "META-INF/vertx/json-mappers.properties"; - /** - * Converts the line endings of generated files to the local OS' line endings, so regenerated - * files don't show up as modified in Git diffs and IDEs. No-op when the separator is LF. - */ - private static final UnaryOperator CONVERT_TO_LOCAL_LINE_SEPARATOR = localLineSeparatorConverter(); + // Converts the line endings of generated files to the local OS' line endings + // so regenerated files don't show up as modified in Git diffs and IDEs + private static final Pattern LINE_BREAK_PATTERN = Pattern.compile("\\r\\n|\\r|\\n"); + private static final UnaryOperator CONVERT_TO_LOCAL_LINE_SEPARATOR = content -> LINE_BREAK_PATTERN.matcher(content).replaceAll(System.lineSeparator()); private File outputDirectory; private List> codeGenerators; @@ -349,13 +348,6 @@ public boolean process(Set annotations, RoundEnvironment return true; } - private static UnaryOperator localLineSeparatorConverter() { - if ("\n".equals(System.lineSeparator())) { - return UnaryOperator.identity(); - } - return content -> content.replaceAll("\n", System.lineSeparator()); - } - private void reportGenException(GenException e) { String name = e.element.toString(); if (e.element.getKind() == ElementKind.METHOD) {