Skip to content

False positive for NON_STATIC_PATTERN_COMPILE_CALL #21

@boris-petrov

Description

@boris-petrov

I have something like:

public final class RegexHelpers {
	private RegexHelpers() {
	}

	public static Pattern getUnescapedSymbolPattern(char symbol) {
		return Pattern.compile(getUnescapedSymbolRegex(symbol));
	}

	public static String getUnescapedSymbolRegex(char symbol) {
		String escapedSymbol = Pattern.quote(String.valueOf(symbol));
		return "(^|[^\\\\])(\\\\\\\\)*" + escapedSymbol; // (^|[^\\])(\\\\)*,
	}
}

Which gives a NON_STATIC_PATTERN_COMPILE_CALL.

I also have another case of a false positive in code like:

	private boolean propertyMatchesText(String test, String text, boolean shouldMatchWholeString) {
		String pcre = SomeHelpers.textToPcre(text, shouldMatchWholeString);
		int caseInsensitiveFlag = isCaseInsensitive() ? Pattern.CASE_INSENSITIVE : 0;
		Pattern pattern = Pattern.compile(pcre, caseInsensitiveFlag | Pattern.UNICODE_CASE);
		return pattern.matcher(test).find();
	}

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