#vulnerable code 
                                private double testModel() {
        try  {

            double runningLoss = 0;
            double runningWeightOfValidationSet = 0;
            boolean gotNextCycle = false;
            int cycle = 0;
            while (dataCycler.hasMore() || gotNextCycle) {
                BufferedWriter trainingWriter = new BufferedWriter(new FileWriter("training" + cycle));
                trainingWriter.write("FileNo");

                for (T instance : dataCycler.getValidationSet()) {
                    trainingWriter.write("" + ((RegressionInstance) instance).id + "\n");
                }
                BufferedWriter testWriter = new BufferedWriter(new FileWriter("test" + cycle));
                testWriter.write("FileNo,actual,predicted\n");
                testWriter = new BufferedWriter(new FileWriter("validation" + cycle));
                List<T> validationSet = dataCycler.getValidationSet();
                double validationSetWeight = getInstanceWeights(validationSet);
                PM predictiveModel = modelBuilder.buildPredictiveModel(dataCycler.getTrainingSet());
                runningLoss += ((RegressionLossChecker) lossChecker).calculateLoss(predictiveModel, validationSet, testWriter) * validationSetWeight;
                runningWeightOfValidationSet += validationSetWeight;
                gotNextCycle = dataCycler.nextCycle();
                cycle++;

                testWriter.flush();
                trainingWriter.flush();
                testWriter.close();
                trainingWriter.close();
            }
            return runningLoss / runningWeightOfValidationSet;
        } catch (IOException e) {
            logger.error("couldn't write");
        }
        return 0.0;
    } 
                            #location 16 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                private double testModel() {
        double runningLoss = 0;
        double runningWeightOfValidationSet = 0;
        boolean gotNextCycle= false;
        while (dataCycler.hasMore() || gotNextCycle){
            List<T> validationSet = dataCycler.getValidationSet();
            double validationSetWeight = getInstanceWeights(validationSet);
            PM predictiveModel = modelBuilder.buildPredictiveModel(dataCycler.getTrainingSet());
            runningLoss += lossChecker.calculateLoss(predictiveModel, validationSet) * validationSetWeight;
            runningWeightOfValidationSet += validationSetWeight;
            gotNextCycle = dataCycler.nextCycle();
        }

        return runningLoss / runningWeightOfValidationSet;
    }