class ErrorMessageExposureDetector extends OpcodeStackDetector {

    private static final String INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE_TYPE = "INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE";
    private BugReporter bugReporter;

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

    @Override
    public void sawOpcode(int seen) {
//        printOpCode(seen);
        if (seen == Const.INVOKEVIRTUAL) {
            String fullClassName = getClassConstantOperand();
            String method = getNameConstantOperand();
            if(isVulnerableClassToPrint(fullClassName) && method.equals("printStackTrace")) {
                if (stack.getStackDepth() > 1) { // If has parameters
                    OpcodeStack.Item parameter = stack.getStackItem(0);
                    if (parameter.getSignature().equals("Ljava/io/PrintStream;") ||
                            parameter.getSignature().equals("Ljava/io/PrintWriter;")) {
                        bugReporter.reportBug(new BugInstance(this,
                                INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE_TYPE,
                                Priorities.NORMAL_PRIORITY)
                                .addClass(this).addMethod(this).addSourceLine(this));
                    }
                } else { // No parameter (only printStackTrace)
                    bugReporter.reportBug(new BugInstance(this,
                            INFORMATION_EXPOSURE_THROUGH_AN_ERROR_MESSAGE_TYPE,
                            Priorities.LOW_PRIORITY)
                            .addClass(this).addMethod(this).addSourceLine(this));
                }
            }
        }
    }

    private boolean isVulnerableClassToPrint(String classConstantOperand) {<FILL_FUNCTION_BODY>}
}

        switch(classConstantOperand) {
            // By following the parent classes of vulnerable class to print
            case "java/lang/Throwable":
            case "java/lang/Exception":
            case "java/lang/Error":

                // By following the recommendation from the CERT Oracle Secure Coding Standard for Java
            case "java/io/FileNotFoundException":
            case "java/sql/SQLException":
            case "java/net/BindException":
            case "java/util/ConcurrentModificationException":
            case "javax/naming/InsufficientResourcesException":
            case "java/util/MissingResourceException":
            case "java/util/jar/JarException":
            case "java/security/acl/NotOwnerException":
            case "java/lang/OutOfMemoryError":
            case "java/lang/StackOverflowError":
                return true;
            default:
                return false;
        }
    
<no_super_class>