Index: /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 10952)
+++ /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 10953)
@@ -34,4 +34,5 @@
 import java.util.Map;
 import java.util.NoSuchElementException;
+import java.util.Optional;
 import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.ForkJoinTask;
@@ -1286,8 +1287,11 @@
         if (!longHalfSegment.isEmpty()) {
             // find the segment with the best quality. If there are several with best quality, the one close to the center is prefered.
-            HalfSegment best = longHalfSegment.stream().max(
+            Optional<HalfSegment> besto = longHalfSegment.stream().max(
                     Comparator.comparingDouble(segment ->
                         segment.quality - 1e-5 * Math.abs(0.5 * (segment.end + segment.start) - 0.5 * pathLength)
-                    )).get();
+                    ));
+            if (!besto.isPresent())
+                throw new IllegalStateException("Unable to find the segment with the best quality for " + way);
+            HalfSegment best = besto.get();
             double remaining = best.end - best.start - rec.getWidth(); // total space left and right from the text
             // The space left and right of the text should be distributed 20% - 80% (towards the center),
