Skip to content

PropertyUtil.propertiesWithPrefix treats prefix as regex pattern #15631

@moomindani

Description

@moomindani

Apache Iceberg version

main (development)

Query engine

No response

Please describe the bug 🐞

PropertyUtil.propertiesWithPrefix uses String.replaceFirst(prefix, "") to strip the prefix from matched keys. Since replaceFirst treats its first argument as a Java regex pattern, prefixes containing regex-special characters (e.g. [, (, +, $) cause incorrect behavior:

  1. Silent mismatch: A prefix like prefix[0]. is valid regex where [0] matches char 0 and . matches any char. After startsWith filtering, the key always starts with the literal prefix, but replaceFirst fails to match the regex at position 0, silently returning the full key instead of stripping the prefix.

  2. PatternSyntaxException: A prefix like prefix[0. contains an unclosed character class, causing replaceFirst to throw PatternSyntaxException.

The fix is to replace replaceFirst(prefix, "") with substring(prefix.length()), which is safe, explicit, and consistent with the startsWith(prefix) filter applied immediately before.

Discovered while investigating #15347.

Willingness to contribute

  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions