Skip to content

PatternSyntaxException on Android: unescaped '}' in TemplateProcessing regex #322

@blundell

Description

@blundell

Description

TemplateProcessing.java line 43 compiles a regex with an unescaped closing brace:

private static final Pattern TEMPLATE_GROUP = Pattern.compile("\\{([\\w$]+(\\.[\\w$]+)*)}");

The trailing } is not escaped. On standard JVM this is accepted (Java's Pattern is lenient about lone }), but on Android the regex engine is backed by ICU (com.android.icu.util.regex.PatternNative), which is strict and rejects it:

java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 22
\{([\w$]+(\.[\w$]+)*)}
                      ^
    at com.android.icu.util.regex.PatternNative.compileImpl(Native Method)
    at com.android.icu.util.regex.PatternNative.<init>(PatternNative.java:53)
    at java.util.regex.Pattern.compile(Pattern.java:1550)
    at java.util.regex.Pattern.<init>(Pattern.java:1426)
    at java.util.regex.Pattern.compile(Pattern.java:1068)
    at com.epam.reportportal.utils.formatting.templating.TemplateProcessing.<clinit>(TemplateProcessing.java:43)

Because this is in the static initializer, the class is permanently poisoned — every subsequent call that touches TemplateProcessing throws ExceptionInInitializerError (or NoClassDefFoundError). This breaks LaunchImpl.startTestItem()applyRequestModifications()applyNameFormat() for all test items.

Impact

Using client-java (any version up to 5.4.14) on Android with Cucumber or any framework that calls startTestItem with parameters causes a crash on devices with strict ICU regex (observed on Samsung devices with recent Android versions). The launch is created successfully, but no test items can be reported.

Reproduction

A minimal Android instrumented test project with:

  • client-java:5.4.13 (or any 5.4.x)
  • agent-java-cucumber6:5.5.7
  • A Cucumber scenario with parameters (triggers applyNameFormat)

Run on a Samsung device (e.g. Galaxy A16). The @Before hook may pass (runs before TemplateProcessing is loaded), but the first scenario step crashes.

Fix

Escape the closing brace in the regex. This is a one-character change:

- private static final Pattern TEMPLATE_GROUP = Pattern.compile("\\{([\\w$]+(\\.[\\w$]+)*)}");
+ private static final Pattern TEMPLATE_GROUP = Pattern.compile("\\{([\\w$]+(\\.[\\w$]+)*)\\}");

\\} is valid on both standard JVM and Android ICU — the fix has no effect on non-Android usage.

Workaround

We are currently patching the string constant in the class bytecode at build time using ASM before dexing. This works but is fragile.

Versions affected

Checked all tags through 5.4.14 — the same unescaped } is present in every version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions