#vulnerable code 
                                public SlocCount countStats(String contents, String languageName) {
        if (contents == null || contents.isEmpty()) {
            return new SlocCount();
        }

        FileClassifierResult fileClassifierResult = this.database.get(languageName);

        State currentState = State.S_BLANK;

        int endPoint = contents.length() - 1;
        String endString = null;
        int linesCount = 0;
        int blankCount = 0;
        int codeCount = 0;
        int commentCount = 0;
        int complexity = 0;

        for (int index=0; index < contents.length(); index++) {
            switch (currentState) {
                case S_BLANK:
                case S_MULTICOMMENT_BLANK:
                    if (this.checkForMatch(contents.charAt(index), index, endPoint, fileClassifierResult.line_comment, contents)) {
                        currentState = State.S_COMMENT;
                        break;
                    }

                    endString = this.checkForMatchMultiOpen(contents.charAt(index), index, endPoint, fileClassifierResult.multi_line, contents);
                    if (endString != null) {
                        currentState = State.S_MULTICOMMENT;
                        break;
                    }

                    endString = this.checkForMatchMultiOpen(contents.charAt(index), index, endPoint, fileClassifierResult.quotes, contents);
                    if (endString != null) {
                        currentState = State.S_STRING;
                        break;
                    }

                    if (!this.isWhitespace(contents.charAt(index))) {
                        currentState = State.S_CODE;

                        if (this.checkForMatch(contents.charAt(index), index, endPoint, fileClassifierResult.complexitychecks, contents)) {
                            complexity++;
                        }
                    }
                    break;
                case S_CODE:
                    endString = this.checkForMatchMultiOpen(contents.charAt(index), index, endPoint, fileClassifierResult.multi_line, contents);
                    if (endString != null) {
                        currentState = State.S_MULTICOMMENT_CODE;
                        break;
                    }

                    endString = this.checkForMatchMultiOpen(contents.charAt(index), index, endPoint, fileClassifierResult.quotes, contents);
                    if (endString != null) {
                        currentState = State.S_STRING;
                        break;
                    } else if (this.checkForMatch(contents.charAt(index), index, endPoint, fileClassifierResult.complexitychecks, contents)) {
                        complexity++;
                    }
                    break;
                case S_STRING:
                    if (contents.charAt(index-1) != '\\' && this.checkForMatchSingle(contents.charAt(index), index, endPoint, endString, contents)) {
                        currentState = State.S_CODE;
                    }
                    break;
                case S_MULTICOMMENT:
                case S_MULTICOMMENT_CODE:
                    if (this.checkForMatchMultiClose(contents.charAt(index), index, endPoint, fileClassifierResult.multi_line, contents)) {
                        if (currentState == State.S_MULTICOMMENT_CODE) {
                            currentState = State.S_CODE;
                        } else {
                            // TODO check if out of bounds
                            if (index + 1 <= endPoint && this.isWhitespace(contents.charAt(index+1))) {
                                currentState = State.S_MULTICOMMENT_BLANK;
                            } else {
                                currentState = State.S_MULTICOMMENT_CODE;
                            }
                        }
                    }
                    break;
            }

            // This means the end of processing the line so calculate the stats according to what state
            // we are currently in
            if (contents.charAt(index) == '\n' || index == endPoint) {
                linesCount++;

                switch (currentState) {
                    case S_BLANK:
                        blankCount++;
                        break;
                    case S_COMMENT:
                    case S_MULTICOMMENT:
                    case S_MULTICOMMENT_BLANK:
                        commentCount++;
                        break;
                    case S_CODE:
                    case S_STRING:
                    case S_COMMENT_CODE:
                    case S_MULTICOMMENT_CODE:
                        codeCount++;
                        break;
                }

                // If we are in a multiline comment that started after some code then we need
                // to move to a multiline comment if a multiline comment then stay there
                // otherwise we reset back into a blank state
                if (currentState != State.S_MULTICOMMENT && currentState != State.S_MULTICOMMENT_CODE) {
                    currentState = State.S_BLANK;
                } else {
                    currentState = State.S_MULTICOMMENT;
                }
            }
        }

        return new SlocCount(linesCount, blankCount, codeCount, commentCount, complexity);
    } 
                            #location 22 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                public SlocCount countStats(String contents, String languageName) {
        if (contents == null || contents.isEmpty()) {
            return new SlocCount();
        }

        FileClassifierResult fileClassifierResult = this.database.get(languageName);

        State currentState = State.S_BLANK;

        int endPoint = contents.length() - 1;
        String endString = null;
        ArrayList<String> endComments = new ArrayList<>();
        int linesCount = 0;
        int blankCount = 0;
        int codeCount = 0;
        int commentCount = 0;
        int complexity = 0;

        for (int index=0; index < contents.length(); index++) {

            if (!isWhitespace(contents.charAt(index))) {
                switch (currentState) {
                    case S_CODE:
                        if (fileClassifierResult.nestedmultiline || endComments.size() == 0) {
                            endString = this.checkForMatchMultiOpen(contents.charAt(index), index, endPoint, fileClassifierResult.multi_line, contents);
                            if (endString != null) {
                                endComments.add(endString);
                                currentState = State.S_MULTICOMMENT_CODE;
                                break;
                            }
                        }

                        if (this.checkForMatch(contents.charAt(index), index, endPoint, fileClassifierResult.line_comment, contents)) {
                            currentState = State.S_COMMENT_CODE;
                            break;
                        }

                        endString = this.checkForMatchMultiOpen(contents.charAt(index), index, endPoint, fileClassifierResult.quotes, contents);
                        if (endString != null) {
                            currentState = State.S_STRING;
                            break;
                        } else if (this.checkForMatch(contents.charAt(index), index, endPoint, fileClassifierResult.complexitychecks, contents)) {
                            complexity++;
                        }
                        break;
                    case S_MULTICOMMENT_BLANK:
                        if (this.checkForMatch(contents.charAt(index), index, endPoint, fileClassifierResult.line_comment, contents)) {
                            currentState = State.S_COMMENT;
                            break;
                        }

                        endString = this.checkForMatchMultiOpen(contents.charAt(index), index, endPoint, fileClassifierResult.multi_line, contents);
                        if (endString != null) {
                            currentState = State.S_MULTICOMMENT;
                            break;
                        }

                        endString = this.checkForMatchMultiOpen(contents.charAt(index), index, endPoint, fileClassifierResult.quotes, contents);
                        if (endString != null) {
                            currentState = State.S_STRING;
                            break;
                        }

                        if (!this.isWhitespace(contents.charAt(index))) {
                            currentState = State.S_CODE;

                            if (this.checkForMatch(contents.charAt(index), index, endPoint, fileClassifierResult.complexitychecks, contents)) {
                                complexity++;
                            }
                        }
                        break;
                    case S_STRING:
                        if (contents.charAt(index - 1) != '\\' && this.checkForMatchSingle(contents.charAt(index), index, endPoint, endString, contents)) {
                            currentState = State.S_CODE;
                        }
                        break;
                    case S_MULTICOMMENT:
                    case S_MULTICOMMENT_CODE:
                        if (this.checkForMatchMultiClose(contents.charAt(index), index, endPoint, fileClassifierResult.multi_line, contents)) {
                            if (currentState == State.S_MULTICOMMENT_CODE) {
                                currentState = State.S_CODE;
                            } else {
                                // TODO check if out of bounds
                                if (index + 1 <= endPoint && this.isWhitespace(contents.charAt(index + 1))) {
                                    currentState = State.S_MULTICOMMENT_BLANK;
                                } else {
                                    currentState = State.S_MULTICOMMENT_CODE;
                                }
                            }
                        }
                        break;
                }
            }

            // This means the end of processing the line so calculate the stats according to what state
            // we are currently in
            if (contents.charAt(index) == '\n' || index == endPoint) {
                linesCount++;

                switch (currentState) {
                    case S_BLANK:
                        blankCount++;
                        break;
                    case S_COMMENT:
                    case S_MULTICOMMENT:
                    case S_MULTICOMMENT_BLANK:
                        commentCount++;
                        break;
                    case S_CODE:
                    case S_STRING:
                    case S_COMMENT_CODE:
                    case S_MULTICOMMENT_CODE:
                        codeCount++;
                        break;
                }

                // If we are in a multiline comment that started after some code then we need
                // to move to a multiline comment if a multiline comment then stay there
                // otherwise we reset back into a blank state
                if (currentState != State.S_MULTICOMMENT && currentState != State.S_MULTICOMMENT_CODE) {
                    currentState = State.S_BLANK;
                } else {
                    currentState = State.S_MULTICOMMENT;
                }
            }
        }

        return new SlocCount(linesCount, blankCount, codeCount, commentCount, complexity);
    }