#vulnerable code 
                                public static GaugeRollup buildFromGaugeRollups(Points<GaugeRollup> input) throws IOException {
        // return the one with the latest timestamp.
        int numSamples = 0;
        Points.Point<GaugeRollup> latest = null;
        for (Points.Point<GaugeRollup> point : input.getPoints().values()) {
            if (latest == null)
                latest = point;
            else if (latest.getTimestamp() < point.getTimestamp())
                latest = point;
            numSamples += point.getData().getNumSamplesUnsafe();
        }
        GaugeRollup newGauge = new GaugeRollup().withGauge(latest.getData().getValue());
        newGauge.numSamples = numSamples;
        return newGauge;
    } 
                            #location 12 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                                public static GaugeRollup buildFromGaugeRollups(Points<GaugeRollup> input) throws IOException {
        GaugeRollup rollup = new GaugeRollup();
        
        rollup.computeFromRollups(BasicRollup.recast(input, IBasicRollup.class));
        
        Points.Point<SimpleNumber> latest = rollup.latestValue;
        
        for (Map.Entry<Long, Points.Point<GaugeRollup>> entry : input.getPoints().entrySet()) {
            if (latest == null || entry.getValue().getTimestamp() > latest.getTimestamp())
                latest = entry.getValue().getData().latestValue;
        }
        
        rollup.latestValue = latest;
        
        return rollup;
    }