#vulnerable code 
                                protected LookupResult extractNode(List<LexicalPatternElement> nextElements, TokenDistributor distributor) {
        int skip = 0;

        for (LexicalPatternElement nextElement : nextElements) {
            if (!nextElement.isWildcard()) {
                break;
            }

            skip++;
        }

        int indexBackup = distributor.getIndex();

        for (int i = skip; i < nextElements.size(); i++) {
            LexicalPatternElement element = nextElements.get(i);
            distributor.setIndex(indexBackup);

            LookupResult result = elementLookupExtractor.extractNode(nextElements.subList(0, skip), element, distributor);
            result.matchedIndex = i;

            if (result.getMergedResults().isMatched()) {
                return result;
            }

            if (element.isOptional()) {
                continue;
            }

            break;
        }

        return new LookupResult();
    } 
                            #location 19 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                protected LookupResult extractNode(List<LexicalPatternElement> nextElements, TokenDistributor distributor) {
        int skip = 0;

        for (LexicalPatternElement nextElement : nextElements) {
            if (!nextElement.isWildcard()) {
                break;
            }

            skip++;
        }

        int indexBackup = distributor.getIndex();

        for (int i = skip; i < nextElements.size(); i++) {
            LexicalPatternElement element = nextElements.get(i);
            distributor.setIndex(indexBackup);

            // consider exclusion of wildcards here

            LookupResult result = elementLookupExtractor.extractNode(nextElements.subList(0, skip), element, distributor);
            result.matchedIndex = i;

            if (result.getMergedResults().isMatched()) {
                return result;
            }

            if (element.isOptional()) {
                continue;
            }

            break;
        }

        return new LookupResult();
    }