Describe the Bug
segmentAndClassifyTrip(points, configs) calls points.getFirst() with no empty check. When points is empty it throws java.util.NoSuchElementException. This is reachable on real paths: inferTransportMode (no-override branch) is called with tripPoints loaded from the DB, which can be empty when a trip's time window contains no surviving raw points (data gaps, pruned/cleaned points). It crashes trip creation and bulk reclassification.
Root Cause
// TransportModeService.segmentAndClassifyTrip, L44-46
List<TripSegment> segments = new ArrayList<>();
List<Double> speeds = calculateSpeeds(points); // tolerates empty
List<RawLocationPoint> currentSegmentPoints = new ArrayList<>();
currentSegmentPoints.add(points.getFirst()); // L46: NoSuchElementException when points is empty
Reachable call paths (no empty-guard before the call):
UnifiedLocationProcessingService.java:770 — trip creation: tripPoints = rawLocationPointJdbcService.findByUserAndTimestampBetweenOrderByTimestampAsc(...)
TransportationModesController.java:208 — reclassifyTrips over existing trips.
Only the transport-mode-override early-return guards inferTransportMode; absent an override, execution reaches L46.
Steps to Reproduce
- Call
inferTransportMode/segmentAndClassifyTrip for a trip whose point list is empty (or create/reclassify a trip whose [startTime,endTime] window has no raw points).
Expected Behavior
Empty points → TransportMode.UNKNOWN (the documented "can't classify" result), no exception.
Observed Behavior (reproduced)
TestFusionUnit__2412__Test.testSegmentAndClassifyTrip_emptyPoints_returnsUnknown:79 » NoSuchElement
java.util.NoSuchElementException
at …TransportModeService.segmentAndClassifyTrip(TransportModeService.java:46)
(testSegmentAndClassifyTrip_singlePoint_returnsUnknown passes — only the empty case fails.)
Suggested Fix
public TransportMode segmentAndClassifyTrip(List<RawLocationPoint> points, List<TransportModeConfig> configs) {
if (points == null || points.isEmpty()) {
return TransportMode.UNKNOWN;
}
...
}
Corresponding Test (generated)
@Test
public void testSegmentAndClassifyTrip_emptyPoints_returnsUnknown() {
// Arrange
List<RawLocationPoint> points = new ArrayList<>();
List<TransportModeConfig> configs = Arrays.asList(
new TransportModeConfig(TransportMode.WALKING, 5.0),
new TransportModeConfig(TransportMode.CYCLING, 20.0),
new TransportModeConfig(TransportMode.DRIVING, null)
);
// Act
TransportMode result = transportModeService.segmentAndClassifyTrip(points, configs);
// Assert
assertEquals(TransportMode.UNKNOWN, result);
}
This input was generated by the test case generator TestFusion developed in our STAR lab.
Describe the Bug
segmentAndClassifyTrip(points, configs)callspoints.getFirst()with no empty check. Whenpointsis empty it throwsjava.util.NoSuchElementException. This is reachable on real paths:inferTransportMode(no-override branch) is called withtripPointsloaded from the DB, which can be empty when a trip's time window contains no surviving raw points (data gaps, pruned/cleaned points). It crashes trip creation and bulk reclassification.Root Cause
Reachable call paths (no empty-guard before the call):
UnifiedLocationProcessingService.java:770— trip creation:tripPoints = rawLocationPointJdbcService.findByUserAndTimestampBetweenOrderByTimestampAsc(...)TransportationModesController.java:208—reclassifyTripsover existing trips.Only the transport-mode-override early-return guards
inferTransportMode; absent an override, execution reaches L46.Steps to Reproduce
inferTransportMode/segmentAndClassifyTripfor a trip whose point list is empty (or create/reclassify a trip whose[startTime,endTime]window has no raw points).Expected Behavior
Empty points →
TransportMode.UNKNOWN(the documented "can't classify" result), no exception.Observed Behavior (reproduced)
(
testSegmentAndClassifyTrip_singlePoint_returnsUnknownpasses — only the empty case fails.)Suggested Fix
Corresponding Test (generated)
This input was generated by the test case generator
TestFusiondeveloped in our STAR lab.