nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: graphhopper/graphhopper
Pull request #1181 (2017-10-07 18:24:00)

Add turn instructions at roundabouts (exit number) in the GPX output data
This PR proposes a fix for #486.

karussell: Thanks!

Patch:
diff --git a/core/src/main/java/com/graphhopper/util/InstructionList.java b/core/src/main/java/com/graphhopper/util/InstructionList.java
index 69d25cc19..331aea5a0 100644
--- a/core/src/main/java/com/graphhopper/util/InstructionList.java
+++ b/core/src/main/java/com/graphhopper/util/InstructionList.java
@@ -254,6 +254,12 @@ public class InstructionList extends AbstractList<Instruction> {
         if (!Double.isNaN(azimuth))
             output.append("<gh:azimuth>").append(Helper.round2(azimuth)).append("</gh:azimuth>");
 
+        if (instruction instanceof RoundaboutInstruction) {
+            RoundaboutInstruction ri = (RoundaboutInstruction) instruction;
+
+            output.append("<gh:exit_number>").append(ri.getExitNumber()).append("</gh:exit_number>");
+        }
+
         output.append("<gh:sign>").append(instruction.getSign()).append("</gh:sign>");
         output.append("</extensions>");
         output.append("</rtept>");


Test patch:
diff --git a/core/src/test/java/com/graphhopper/util/InstructionListTest.java b/core/src/test/java/com/graphhopper/util/InstructionListTest.java
index 66ef13394..06d7aba54 100644
--- a/core/src/test/java/com/graphhopper/util/InstructionListTest.java
+++ b/core/src/test/java/com/graphhopper/util/InstructionListTest.java
@@ -387,6 +387,28 @@ public class InstructionListTest {
         assertNotNull(write(json));
     }
 
+    @Test
+    public void testCreateGPXIncludesRoundaboutExitNumber() {
+        InstructionList instructions = new InstructionList(usTR);
+
+        PointList pl = new PointList();
+        pl.add(52.555423473315, 13.43890086052345);
+        pl.add(52.555550691982, 13.43946393816465);
+        pl.add(52.555619423589, 13.43886994061328);
+        RoundaboutInstruction instr = new RoundaboutInstruction(Instruction.USE_ROUNDABOUT, "streetname",
+                InstructionAnnotation.EMPTY, pl)
+                .setRadian(2.058006514284998d)
+                .setExitNumber(3)
+                .setExited();
+        instructions.add(instr);
+        instructions.add(new FinishInstruction(52.555619423589, 13.43886994061328, 0));
+
+        String gpxStr = instructions.createGPX("test", 0, true, true, false, false);
+
+        assertTrue(gpxStr, gpxStr.contains("<gh:exit_number>3</gh:exit_number>"));
+        verifyGPX(gpxStr);
+    }
+
     @Test
     public void testCreateGPXWithEle() {
         final List<GPXEntry> fakeList = new ArrayList<GPXEntry>();
Repository: graphhopper/graphhopper
Pull request #1442 (2018-08-21 13:09:35)

Allow configuring the precision of the polyline encoding
As discussed in https://github.com/graphhopper/graphhopper-navigation/issues/1, we should make the precision of the polyline encoding configureable. 

This PR adds the option to change the precision of the Polyline encoding to use for example a precision of `1e6` as used by OSRM/Mapbox.


Patch:
diff --git a/web-api/src/main/java/com/graphhopper/http/WebHelper.java b/web-api/src/main/java/com/graphhopper/http/WebHelper.java
index 84aeac6fd..4d2e4d179 100644
--- a/web-api/src/main/java/com/graphhopper/http/WebHelper.java
+++ b/web-api/src/main/java/com/graphhopper/http/WebHelper.java
@@ -102,16 +102,20 @@ public class WebHelper {
     }
 
     public static String encodePolyline(PointList poly, boolean includeElevation) {
+        return encodePolyline(poly, includeElevation, 1e5);
+    }
+
+    public static String encodePolyline(PointList poly, boolean includeElevation, double precision) {
         StringBuilder sb = new StringBuilder();
         int size = poly.getSize();
         int prevLat = 0;
         int prevLon = 0;
         int prevEle = 0;
         for (int i = 0; i < size; i++) {
-            int num = (int) Math.floor(poly.getLatitude(i) * 1e5);
+            int num = (int) Math.floor(poly.getLatitude(i) * precision);
             encodeNumber(sb, num - prevLat);
             prevLat = num;
-            num = (int) Math.floor(poly.getLongitude(i) * 1e5);
+            num = (int) Math.floor(poly.getLongitude(i) * precision);
             encodeNumber(sb, num - prevLon);
             prevLon = num;
             if (includeElevation) {


Test patch:
diff --git a/web-api/src/test/java/com/graphhopper/http/WebHelperTest.java b/web-api/src/test/java/com/graphhopper/http/WebHelperTest.java
index 2661cad3e..e78c4c302 100644
--- a/web-api/src/test/java/com/graphhopper/http/WebHelperTest.java
+++ b/web-api/src/test/java/com/graphhopper/http/WebHelperTest.java
@@ -74,4 +74,9 @@ public class WebHelperTest {
         assertEquals("_p~iF~ps|Uo}@_ulLnnqC_anF_mqNvxq`@?", WebHelper.encodePolyline(
                 Helper.createPointList3D(38.5, -120.2, 10, 40.7, -120.95, 1234, 43.252, -126.453, 1234)));
     }
+
+    @Test
+    public void testEncode1e6() throws Exception {
+        assertEquals("ohdfzAgt}bVoEL", WebHelper.encodePolyline(Helper.createPointList(47.827608, 12.123476, 47.827712, 12.123469), false, 1e6));
+    }
 }
Repository: graphhopper/graphhopper
Pull request #901 (2016-12-06 18:18:17)

Accept keys "cycleway:left" and "cycleway:right"  with "opposite" values
This change implements access issue for bicycles as discussed in #280.


Patch:
diff --git a/android/build.gradle b/android/build.gradle
index a9cd00795..11a13c7c5 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -4,7 +4,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.2.2'
+        classpath 'com.android.tools.build:gradle:2.2.3'
     }
 }
 
diff --git a/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java b/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java
index d567368c7..38e0287ca 100644
--- a/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java
+++ b/core/src/main/java/com/graphhopper/routing/util/BikeCommonFlagEncoder.java
@@ -671,7 +671,9 @@ public class BikeCommonFlagEncoder extends AbstractFlagEncoder {
         if ((isOneway || way.hasTag("junction", "roundabout"))
                 && !way.hasTag("oneway:bicycle", "no")
                 && !way.hasTag("bicycle:backward")
-                && !way.hasTag("cycleway", oppositeLanes)) {
+                && !way.hasTag("cycleway", oppositeLanes)
+                && !way.hasTag("cycleway:left", oppositeLanes)
+                && !way.hasTag("cycleway:right", oppositeLanes)) {
             boolean isBackward = way.hasTag("oneway", "-1")
                     || way.hasTag("oneway:bicycle", "-1")
                     || way.hasTag("vehicle:forward", "no")


Test patch:
diff --git a/core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java b/core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java
index 57455a134..95a99e3cb 100644
--- a/core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java
+++ b/core/src/test/java/com/graphhopper/routing/util/BikeFlagEncoderTest.java
@@ -394,6 +394,14 @@ public class BikeFlagEncoderTest extends AbstractBikeFlagEncoderTester {
         flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0);
         assertTrue(encoder.isForward(flags));
         assertTrue(encoder.isBackward(flags));
+
+        way.clearTags();
+        way.setTag("highway", "residential");
+        way.setTag("oneway", "yes");
+        way.setTag("cycleway:left", "opposite_lane");
+        flags = encoder.handleWayTags(way, encoder.acceptWay(way), 0);
+        assertTrue(encoder.isForward(flags));
+        assertTrue(encoder.isBackward(flags));
     }
 
     @Test
Repository: graphhopper/graphhopper
Pull request #906 (2016-12-09 23:06:10)

CH-Preparation of Generic Vehicle
We introduced a small bug with the Generic weighting. When we pass a null Graph on initialization, we try to get the NodeAccess, which results in a null-pointer exception.

karussell: Thanks!

Patch:
diff --git a/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java b/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java
index ca960eebb..1b6c9e226 100644
--- a/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java
+++ b/core/src/main/java/com/graphhopper/routing/weighting/GenericWeighting.java
@@ -162,6 +162,8 @@ public class GenericWeighting extends AbstractWeighting {
      * Use this method to associate a graph with this weighting to calculate e.g. node locations too.
      */
     public void setGraph(Graph graph) {
+        if(graph == null)
+            return;
         this.na = graph.getNodeAccess();
     }
 }


Test patch:
diff --git a/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java b/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java
index dde677609..02f0ca3d1 100644
--- a/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java
+++ b/core/src/test/java/com/graphhopper/routing/weighting/GenericWeightingTest.java
@@ -106,4 +106,11 @@ public class GenericWeightingTest {
         EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
         assertEquals(edgeWeight, weighting.calcMillis(edge, false, EdgeIterator.NO_EDGE), .1);
     }
+
+    @Test
+    public void testNullGraph() {
+        ConfigMap cMap = encoder.readStringMap(new PMap());
+        GenericWeighting weighting = new GenericWeighting(encoder, cMap);
+        weighting.setGraph(null);
+    }
 }
Repository: CycloneDX/cyclonedx-core-java
Pull request #204 (2022-05-30 08:39:08)

Checked For Index Out Of Bounds
It is possible at the moment for a user of ```BomParserFactory.createParser(byte[])``` to throw a IndexOutOfBoundsException if they pass in a empty array.  

I have added in a if statement to check the length of the array so this cannot happen. 


Patch:
diff --git a/src/main/java/org/cyclonedx/BomParserFactory.java b/src/main/java/org/cyclonedx/BomParserFactory.java
index f0f5b28a3..8ae0fa34f 100644
--- a/src/main/java/org/cyclonedx/BomParserFactory.java
+++ b/src/main/java/org/cyclonedx/BomParserFactory.java
@@ -43,6 +43,10 @@ public class BomParserFactory {
     }
 
     public static Parser createParser(final byte[] bytes) throws ParseException {
+        if(bytes.length < 1) {
+            throw new ParseException("Cannot create parser from empty byte array.");
+        }
+
         if (bytes[0] == 123) {
             return new JsonParser();
         } else if (bytes[0] == 60) {


Test patch:
diff --git a/src/test/java/org/cyclonedx/BomParserFactoryTest.java b/src/test/java/org/cyclonedx/BomParserFactoryTest.java
index fbc92ed68..33602b878 100644
--- a/src/test/java/org/cyclonedx/BomParserFactoryTest.java
+++ b/src/test/java/org/cyclonedx/BomParserFactoryTest.java
@@ -18,12 +18,14 @@
  */
 package org.cyclonedx;
 
+import org.cyclonedx.exception.ParseException;
 import org.cyclonedx.parsers.JsonParser;
 import org.cyclonedx.parsers.Parser;
 import org.cyclonedx.parsers.XmlParser;
 import org.junit.jupiter.api.Test;
 import java.io.File;
 
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class BomParserFactoryTest {
@@ -39,4 +41,12 @@ public class BomParserFactoryTest {
         Parser parser = BomParserFactory.createParser(new File(BomParserFactory.class.getResource("/bom-1.2.json").getFile()));
         assertTrue(parser instanceof JsonParser);
     }
+
+    @Test()
+    public void testFactoryThrowsParseExceptionWithEmptyData() {
+        byte[] emptyData = new byte[]{};
+        assertThrows(ParseException.class, () ->
+            BomParserFactory.createParser(emptyData)
+        );
+    }
 }
Repository: google/jax
Pull request #22790 (2024-07-31 16:13:40)

jax.extend.backend: add semi-private backend utils from xla_bridge
jax.extend.backend: add semi-private backend utils from xla_bridge

For context, see https://jax.readthedocs.io/en/latest/jep/15856-jex.html.



Patch:
diff --git a/jax/extend/BUILD b/jax/extend/BUILD
index 229b6cd6e..babe0c8b1 100644
--- a/jax/extend/BUILD
+++ b/jax/extend/BUILD
@@ -57,7 +57,10 @@ pytype_strict_library(
 pytype_strict_library(
     name = "backend",
     srcs = ["backend.py"],
-    deps = ["//jax"],
+    deps = [
+        "//jax",
+        "//jax:xla_bridge",
+    ],
 )
 
 pytype_strict_library(
diff --git a/jax/extend/backend.py b/jax/extend/backend.py
index 7aa2c8a06..25d41d9a2 100644
--- a/jax/extend/backend.py
+++ b/jax/extend/backend.py
@@ -18,3 +18,10 @@
 from jax._src.api import (
   clear_backends as clear_backends,
 )
+from jax._src.xla_bridge import (
+  backends as backends,
+  backend_xla_version as backend_xla_version,
+  default_backend as default_backend,
+  get_backend as get_backend,
+  register_backend_factory as register_backend_factory,
+)


Test patch:
diff --git a/tests/extend_test.py b/tests/extend_test.py
index 939b4d3c4..055516d41 100644
--- a/tests/extend_test.py
+++ b/tests/extend_test.py
@@ -28,6 +28,7 @@ from jax._src import core
 from jax._src import linear_util
 from jax._src import prng
 from jax._src import test_util as jtu
+from jax._src import xla_bridge
 from jax._src.interpreters import mlir
 from jax._src.lib.mlir import ir
 from jax._src.extend import ffi
@@ -47,7 +48,12 @@ class ExtendTest(jtu.JaxTestCase):
     self.assertIs(jex.random.unsafe_rbg_prng_impl, prng.unsafe_rbg_prng_impl)
 
     # Assume these are tested elsewhere, only check equivalence
+    self.assertIs(jex.backend.backends, xla_bridge.backends)
+    self.assertIs(jex.backend.backend_xla_version, xla_bridge.backend_xla_version)
+    self.assertIs(jex.backend.default_backend, xla_bridge.default_backend)
     self.assertIs(jex.backend.clear_backends, api.clear_backends)
+    self.assertIs(jex.backend.get_backend, xla_bridge.get_backend)
+    self.assertIs(jex.backend.register_backend_factory, xla_bridge.register_backend_factory)
     self.assertIs(jex.core.array_types, abstract_arrays.array_types)
     self.assertIs(jex.linear_util.StoreException, linear_util.StoreException)
     self.assertIs(jex.linear_util.WrappedFun, linear_util.WrappedFun)