Skip to content

Pattern.pattern() not return @Regex String #7539

@Marat-Tim

Description

@Marat-Tim

I have such code

import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) {
        Pattern abc = Pattern.compile("abc");
        String str = abc.pattern();
        System.out.println("abc".replaceAll(str, ""));
    }
}

And such checker framework config

plugins {
    id("org.checkerframework").version("1.0.2")
}

checkerFramework {
    version = "3.54.0"
    checkers = listOf(
        "org.checkerframework.checker.regex.RegexChecker"
    )
}

I get this error

Main.java:7: error: [argument] incompatible argument for parameter regex of String.replaceAll.
        System.out.println("abc".replaceAll(str, ""));
                                            ^
  found   : String
  required: @Regex String
1 error

It seems that Pattern.pattern() should always return @Regex String, shouldn't it?

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