#vulnerable code 
                                private double calculateError(Dataframe trainingData, Map<List<Object>, Double> thitas) {
        //The cost function as described on http://ufldl.stanford.edu/wiki/index.php/Softmax_Regression
        //It is optimized for speed to reduce the amount of loops
        double error=0.0;
        
        for(Record r : trainingData) { 
            AssociativeArray classProbabilities = hypothesisFunction(r.getX(), thitas);
            Double score = classProbabilities.getDouble(r.getY());
            error+=Math.log(score); //no need to loop through the categories. Just grab the one that we are interested in
        }
        
        return -error/kb().getModelParameters().getN();
    } 
                            #location 9 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                private double calculateError(Dataframe trainingData, Map<List<Object>, Double> thitas) {
        //The cost function as described on http://ufldl.stanford.edu/wiki/index.php/Softmax_Regression
        //It is optimized for speed to reduce the amount of loops
        
        double error = StreamMethods.stream(trainingData.stream(), isParallelized()).mapToDouble(r -> { 
            AssociativeArray classProbabilities = hypothesisFunction(r.getX(), thitas);
            Double score = classProbabilities.getDouble(r.getY());
            return Math.log(score); //no need to loop through the categories. Just grab the one that we are interested in
        }).sum();
        
        return -error/kb().getModelParameters().getN();
    }