class ReDosDetector extends OpcodeStackDetector {

    private static final String REDOS_TYPE = "REDOS";

    private static final InvokeMatcherBuilder PATTERN_COMPILE = invokeInstruction().atClass("java/util/regex/Pattern")
            .atMethod("compile").withArgs("(Ljava/lang/String;)Ljava/util/regex/Pattern;");
    private static final InvokeMatcherBuilder STRING_MATCHES = invokeInstruction().atClass("java/lang/String")
            .atMethod("matches").withArgs("(Ljava/lang/String;)Z");

    private BugReporter bugReporter;

    public ReDosDetector(BugReporter bugReporter) {
        this.bugReporter = bugReporter;
    }

    @Override
    public void sawOpcode(int seen) {<FILL_FUNCTION_BODY>}


}



        //printOpCode(seen);
        //IMPORTANT: Both API are regroup in the same condition because they both have one input string parameter.
        if (seen == Const.INVOKESTATIC && PATTERN_COMPILE.matches(this)
                || seen == Const.INVOKEVIRTUAL && STRING_MATCHES.matches(this)) {

            OpcodeStack.Item item = stack.getStackItem(0);



            if (!StackUtils.isVariableString(item)) {
                String regex = (String) item.getConstant();

                RegexRedosAnalyzer analyzer = new RegexRedosAnalyzer();
                analyzer.analyseRegexString(regex);

                //Reporting the issue
                if(analyzer.isVulnerable()) {
                    MethodDescriptor md = this.getMethodDescriptor();
                    FieldDescriptor fd = this.getFieldDescriptor();

                    BugInstance bug = new BugInstance(this, REDOS_TYPE, Priorities.NORMAL_PRIORITY) //
                            .addString(regex).addClass(this);
                    if (md != null)
                        bug.addMethod(md);
                    if (fd != null)
                        bug.addField(fd);

                    try {
                        bug.addSourceLine(this);
                    } catch (IllegalStateException e) {
                    }

                    bugReporter.reportBug(bug);
                }
            }

        }
    
<no_super_class>