#vulnerable code 
                                public String indexDataset(Dataset dataset) {
        logger.info("indexing dataset " + dataset.getId());
        Collection<SolrInputDocument> docs = new ArrayList<>();
        List<String> dataversePathSegmentsAccumulator = new ArrayList<>();
//        List<String> dataverseSegments = null;
//        try {
//            dataverseSegments = findPathSegments(dataset.getOwner(), dataversePathSegmentsAccumulator);
//        } catch (Exception ex) {
//            logger.info("failed to find dataverseSegments for dataversePaths for " + SearchFields.SUBTREE + ": " + ex);
//        }
//        List<String> dataversePaths = getDataversePathsFromSegments(dataverseSegments);
        SolrInputDocument solrInputDocument = new SolrInputDocument();
        solrInputDocument.addField(SearchFields.ID, "dataset_" + dataset.getId());
        solrInputDocument.addField(SearchFields.ENTITY_ID, dataset.getId());
        solrInputDocument.addField(SearchFields.TYPE, "datasets");
        /**
         * @todo: should we assign a dataset title to name like this?
         */
        if (dataset.getLatestVersion() != null) {
            if (dataset.getLatestVersion().getMetadata() != null) {
                if (dataset.getLatestVersion().getMetadata().getAuthorsStr() != null) {
                    if (!dataset.getLatestVersion().getMetadata().getAuthorsStr().isEmpty()) {
                        solrInputDocument.addField(SearchFields.AUTHOR_STRING, dataset.getLatestVersion().getMetadata().getAuthorsStr());
                    } else {
                        logger.info("author string was empty");
                    }
                } else {
                    logger.info("dataset.getLatestVersion().getMetadata().getAuthorsStr() was null");
                }
                if (dataset.getLatestVersion().getMetadata().getTitle() != null) {
                    if (!dataset.getLatestVersion().getMetadata().getTitle().isEmpty()) {
                        solrInputDocument.addField(SearchFields.TITLE, dataset.getLatestVersion().getMetadata().getTitle());
                    }
                    else {
                        logger.info("title was empty");
                    }
                }
                if (dataset.getLatestVersion().getMetadata().getProductionDate() != null) {
                    /**
                     * @todo: clean this up, DRY
                     */
                    SimpleDateFormat inputDateyyyy = new SimpleDateFormat("yyyy", Locale.ENGLISH);
                    try {
                        Date citationDate = inputDateyyyy.parse(dataset.getLatestVersion().getMetadata().getProductionDate());
                        solrInputDocument.addField(SearchFields.CITATION_DATE, citationDate);
                        SimpleDateFormat yearOnly = new SimpleDateFormat("yyyy");
                        String citationYear = yearOnly.format(citationDate);
                        solrInputDocument.addField(SearchFields.CITATION_YEAR, Integer.parseInt(citationYear));
                    } catch (Exception ex) {
                        logger.info("Can't convert " + dataset.getLatestVersion().getMetadata().getProductionDate() + " to a YYYY date from dataset " + dataset.getId());
                    }
                    SimpleDateFormat inputDateyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
                    try {
                        Date citationDate = inputDateyyyyMMdd.parse(dataset.getLatestVersion().getMetadata().getProductionDate());
                        solrInputDocument.addField(SearchFields.CITATION_DATE, citationDate);
                        SimpleDateFormat yearOnly = new SimpleDateFormat("yyyy");
                        String citationYear = yearOnly.format(citationDate);
                        solrInputDocument.addField(SearchFields.CITATION_YEAR, Integer.parseInt(citationYear));
                    } catch (Exception ex) {
                        logger.info("Can't convert " + dataset.getLatestVersion().getMetadata().getProductionDate() + " to a YYYY-MM-DD date from dataset " + dataset.getId());
                    }
                }
                else {
                    logger.info("dataset.getLatestVersion().getMetadata().getTitle() was null");
                }
            } else {
                logger.info("dataset.getLatestVersion().getMetadata() was null");
            }

        } else {
            logger.info("dataset.getLatestVersion() was null");
        }
        /**
         * @todo: don't use distributor for category. testing facets
         */
       // solrInputDocument.addField(SearchFields.CATEGORY, dataset.getDistributor());
        if (dataset.getDescription() != null && !dataset.getDescription().isEmpty()) {
            solrInputDocument.addField(SearchFields.DESCRIPTION, dataset.getDescription());
        }
//        solrInputDocument.addField(SearchFields.SUBTREE, dataversePaths);
        solrInputDocument.addField(SearchFields.ORIGINAL_DATAVERSE, dataset.getOwner().getName());
        solrInputDocument.addField(SearchFields.PARENT_TYPE, "datasets");
        solrInputDocument.addField(SearchFields.PARENT_ID, dataset.getOwner().getId());
        solrInputDocument.addField(SearchFields.PARENT_NAME, dataset.getOwner().getName());

        docs.add(solrInputDocument);

        List<DataFile> files = dataset.getFiles();
        for (DataFile dataFile : files) {
            SolrInputDocument datafileSolrInputDocument = new SolrInputDocument();
            datafileSolrInputDocument.addField(SearchFields.ID, "datafile_" + dataFile.getId());
            datafileSolrInputDocument.addField(SearchFields.ENTITY_ID, dataFile.getId());
            datafileSolrInputDocument.addField(SearchFields.TYPE, "files");
            datafileSolrInputDocument.addField(SearchFields.NAME, dataFile.getName());
            datafileSolrInputDocument.addField(SearchFields.FILE_TYPE, dataFile.getContentType());
            datafileSolrInputDocument.addField(SearchFields.FILE_TYPE_GROUP, dataFile.getContentType().split("/")[0]);
//            datafileSolrInputDocument.addField(SearchFields.SUBTREE, dataversePaths);
            datafileSolrInputDocument.addField(SearchFields.ORIGINAL_DATAVERSE, dataFile.getOwner().getOwner().getName());
            datafileSolrInputDocument.addField(SearchFields.PARENT_TYPE, "datasets");
           // datafileSolrInputDocument.addField(SearchFields.PARENT_NAME, dataFile.getDataset().getTitle());
            datafileSolrInputDocument.addField(SearchFields.PARENT_ID, dataFile.getOwner().getId());
            if (!dataFile.getOwner().getLatestVersion().getMetadata().getTitle().isEmpty()) {
                datafileSolrInputDocument.addField(SearchFields.PARENT_NAME, dataFile.getOwner().getLatestVersion().getMetadata().getTitle());
            }
            docs.add(datafileSolrInputDocument);
        }

        /**
         * @todo allow for configuration of hostname and port
         */
        SolrServer server = new HttpSolrServer("http://localhost:8983/solr/");

        try {
            server.add(docs);
        } catch (SolrServerException | IOException ex) {
            return ex.toString();
        }
        try {
            server.commit();
        } catch (SolrServerException | IOException ex) {
            return ex.toString();
        }

        return "indexed dataset " + dataset.getId(); // + ":" + dataset.getTitle();
    } 
                            #location 81 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                public String indexDataset(Dataset dataset) {
        logger.info("indexing dataset " + dataset.getId());
        Collection<SolrInputDocument> docs = new ArrayList<>();
        List<String> dataversePathSegmentsAccumulator = new ArrayList<>();
        List<String> dataverseSegments = null;
        try {
            dataverseSegments = findPathSegments(dataset.getOwner(), dataversePathSegmentsAccumulator);
        } catch (Exception ex) {
            logger.info("failed to find dataverseSegments for dataversePaths for " + SearchFields.SUBTREE + ": " + ex);
        }
        List<String> dataversePaths = getDataversePathsFromSegments(dataverseSegments);
        SolrInputDocument solrInputDocument = new SolrInputDocument();
        solrInputDocument.addField(SearchFields.ID, "dataset_" + dataset.getId());
        solrInputDocument.addField(SearchFields.ENTITY_ID, dataset.getId());
        solrInputDocument.addField(SearchFields.TYPE, "datasets");
        /**
         * @todo: should we assign a dataset title to name like this?
         */
        if (dataset.getLatestVersion() != null) {
            if (dataset.getLatestVersion().getMetadata() != null) {
                if (dataset.getLatestVersion().getMetadata().getAuthorsStr() != null) {
                    if (!dataset.getLatestVersion().getMetadata().getAuthorsStr().isEmpty()) {
                        solrInputDocument.addField(SearchFields.AUTHOR_STRING, dataset.getLatestVersion().getMetadata().getAuthorsStr());
                    } else {
                        logger.info("author string was empty");
                    }
                } else {
                    logger.info("dataset.getLatestVersion().getMetadata().getAuthorsStr() was null");
                }
                if (dataset.getLatestVersion().getMetadata().getTitle() != null) {
                    if (!dataset.getLatestVersion().getMetadata().getTitle().isEmpty()) {
                        solrInputDocument.addField(SearchFields.TITLE, dataset.getLatestVersion().getMetadata().getTitle());
                    }
                    else {
                        logger.info("title was empty");
                    }
                }
                if (dataset.getLatestVersion().getMetadata().getProductionDate() != null) {
                    /**
                     * @todo: clean this up, DRY
                     */
                    SimpleDateFormat inputDateyyyy = new SimpleDateFormat("yyyy", Locale.ENGLISH);
                    try {
                        Date citationDate = inputDateyyyy.parse(dataset.getLatestVersion().getMetadata().getProductionDate());
                        solrInputDocument.addField(SearchFields.CITATION_DATE, citationDate);
                        SimpleDateFormat yearOnly = new SimpleDateFormat("yyyy");
                        String citationYear = yearOnly.format(citationDate);
                        solrInputDocument.addField(SearchFields.CITATION_YEAR, Integer.parseInt(citationYear));
                    } catch (Exception ex) {
                        logger.info("Can't convert " + dataset.getLatestVersion().getMetadata().getProductionDate() + " to a YYYY date from dataset " + dataset.getId());
                    }
                    SimpleDateFormat inputDateyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
                    try {
                        Date citationDate = inputDateyyyyMMdd.parse(dataset.getLatestVersion().getMetadata().getProductionDate());
                        solrInputDocument.addField(SearchFields.CITATION_DATE, citationDate);
                        SimpleDateFormat yearOnly = new SimpleDateFormat("yyyy");
                        String citationYear = yearOnly.format(citationDate);
                        solrInputDocument.addField(SearchFields.CITATION_YEAR, Integer.parseInt(citationYear));
                    } catch (Exception ex) {
                        logger.info("Can't convert " + dataset.getLatestVersion().getMetadata().getProductionDate() + " to a YYYY-MM-DD date from dataset " + dataset.getId());
                    }
                }
                else {
                    logger.info("dataset.getLatestVersion().getMetadata().getTitle() was null");
                }
            } else {
                logger.info("dataset.getLatestVersion().getMetadata() was null");
            }

        } else {
            logger.info("dataset.getLatestVersion() was null");
        }
        /**
         * @todo: don't use distributor for category. testing facets
         */
       // solrInputDocument.addField(SearchFields.CATEGORY, dataset.getDistributor());
        if (dataset.getDescription() != null && !dataset.getDescription().isEmpty()) {
            solrInputDocument.addField(SearchFields.DESCRIPTION, dataset.getDescription());
        }
        solrInputDocument.addField(SearchFields.SUBTREE, dataversePaths);
        solrInputDocument.addField(SearchFields.ORIGINAL_DATAVERSE, dataset.getOwner().getName());
        solrInputDocument.addField(SearchFields.PARENT_TYPE, "datasets");
        solrInputDocument.addField(SearchFields.PARENT_ID, dataset.getOwner().getId());
        solrInputDocument.addField(SearchFields.PARENT_NAME, dataset.getOwner().getName());

        docs.add(solrInputDocument);

        List<DataFile> files = dataset.getFiles();
        for (DataFile dataFile : files) {
            SolrInputDocument datafileSolrInputDocument = new SolrInputDocument();
            datafileSolrInputDocument.addField(SearchFields.ID, "datafile_" + dataFile.getId());
            datafileSolrInputDocument.addField(SearchFields.ENTITY_ID, dataFile.getId());
            datafileSolrInputDocument.addField(SearchFields.TYPE, "files");
            datafileSolrInputDocument.addField(SearchFields.NAME, dataFile.getName());
            datafileSolrInputDocument.addField(SearchFields.FILE_TYPE, dataFile.getContentType());
            datafileSolrInputDocument.addField(SearchFields.FILE_TYPE_GROUP, dataFile.getContentType().split("/")[0]);
            datafileSolrInputDocument.addField(SearchFields.SUBTREE, dataversePaths);
            datafileSolrInputDocument.addField(SearchFields.ORIGINAL_DATAVERSE, dataFile.getOwner().getOwner().getName());
            datafileSolrInputDocument.addField(SearchFields.PARENT_TYPE, "datasets");
           // datafileSolrInputDocument.addField(SearchFields.PARENT_NAME, dataFile.getDataset().getTitle());
            datafileSolrInputDocument.addField(SearchFields.PARENT_ID, dataFile.getOwner().getId());
            if (!dataFile.getOwner().getLatestVersion().getMetadata().getTitle().isEmpty()) {
                datafileSolrInputDocument.addField(SearchFields.PARENT_NAME, dataFile.getOwner().getLatestVersion().getMetadata().getTitle());
            }
            docs.add(datafileSolrInputDocument);
        }

        /**
         * @todo allow for configuration of hostname and port
         */
        SolrServer server = new HttpSolrServer("http://localhost:8983/solr/");

        try {
            server.add(docs);
        } catch (SolrServerException | IOException ex) {
            return ex.toString();
        }
        try {
            server.commit();
        } catch (SolrServerException | IOException ex) {
            return ex.toString();
        }

        return "indexed dataset " + dataset.getId(); // + ":" + dataset.getTitle();
    }