Skip to content

GraphBatch.newEdge() writes a null for a declared edge property as a type tag with no value, so the edge reads back weight=-1 or since=2, or is logged as corrupted (also through POST /api/v1/batch) #9018

Closed

Description

@tae898

When an edge type declares a property and GraphBatch.newEdge() is given null for it, the stored edge does not hold null. The repro creates the same three edges through Vertex.newEdge() and through GraphBatch.newEdge(). Vertex.newEdge() stores weight=null, since=null, and label=null. GraphBatch.newEdge() stores edges that read back weight=-1 (the edge where note=hello follows it), since=2 (where weight=7 follows it), and label=null, and reading that last edge logs SEVER [BinarySerializer] Possible corrupted record #4:2050 with a java.nio.BufferUnderflowException. When the batch also holds an edge of a second type, the same three edges are stored correctly.

The batch path that serializes edges itself takes the type tag of a declared property from the schema (GraphBatch.java#L1126-L1136), writes the tag, and then writes no bytes for a null value (#L1210-L1218, #L1239-L1241), so the reader takes the bytes that follow as the value, or runs past the end of the record. An undeclared property gets its tag from the value (BinaryTypes.getTypeFromValue), which is the null tag for null. When the edges of one flush span more than one bucket, the serialized buffers are discarded and each edge is created through MutableEdge instead (#L1351-L1365), which is the path the mixed batch takes.

The HTTP batch endpoint reaches the same method: PostBatchHandler passes the properties of a JSONL edge line to GraphBatch.newEdge() as they were parsed (PostBatchHandler.java#L1784, BatchRecord.java#L67-L79). The second repro posts {"@type":"edge","@class":"E","@from":"a","@to":"b","name":"x","weight":null,"note":"hello"} to /api/v1/batch/repro, and the edge reads back weight=-1. (Its other two lines belong to #9019, on the same path: a SHORT is wrapped and a MANDATORY property is not enforced.)

Related: #7448 (fixed) was the header offset of property-less GraphBatch edges; #4142 (fixed) was DATETIME parsing of edge properties in /batch; #6061 (fixed) was a Map value in RemoteGraphBatch. None of them is about a null value.

Repro

# lib/ holds the engine jar built at the commit under test and its dependencies; the second repro also needs arcadedb-server and arcadedb-network
javac -cp "lib/*" GraphBatchNullEdgeProperty.java
java -XX:+UseCompactObjectHeaders --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED -cp "lib/*:." GraphBatchNullEdgeProperty ./db
import com.arcadedb.database.*;
import com.arcadedb.graph.*;

public class GraphBatchNullEdgeProperty {
  public static void main(String[] args) {
    System.out.println("ArcadeDB " + com.arcadedb.Constants.getRawVersion() + " (" + com.arcadedb.Constants.getBuildNumber() + "), Java "
        + System.getProperty("java.version"));
    try (Database db = new DatabaseFactory(args[0]).create()) {
      db.command("sql", "CREATE VERTEX TYPE N");
      db.command("sql", "CREATE EDGE TYPE E");
      db.command("sql", "CREATE EDGE TYPE F");
      db.command("sql", "CREATE PROPERTY E.weight INTEGER");
      db.command("sql", "CREATE PROPERTY E.since LONG");
      db.command("sql", "CREATE PROPERTY E.label STRING");
      final RID[] v = new RID[6];
      db.transaction(() -> {
        for (int i = 0; i < 6; i++)
          v[i] = db.newVertex("N").set("id", i).save().getIdentity();
      });

      // the same three edges through Vertex.newEdge() and through GraphBatch.newEdge()
      db.transaction(() -> {
        final MutableVertex a = db.lookupByRID(v[0], true).asVertex().modify();
        a.newEdge("E", v[1], "weight", null, "note", "hello");
        a.newEdge("E", v[1], "since", null, "weight", 7);
        a.newEdge("E", v[1], "weight", 7, "label", null);
      });
      try (GraphBatch batch = db.batch().build()) {
        batch.newEdge(v[2], "E", v[3], "weight", null, "note", "hello");
        batch.newEdge(v[2], "E", v[3], "since", null, "weight", 7);
        batch.newEdge(v[2], "E", v[3], "weight", 7, "label", null);
      }
      try (GraphBatch batch = db.batch().build()) {
        batch.newEdge(v[4], "E", v[5], "weight", null, "note", "hello");
        batch.newEdge(v[4], "E", v[5], "since", null, "weight", 7);
        batch.newEdge(v[4], "E", v[5], "weight", 7, "label", null);
        batch.newEdge(v[4], "F", v[5]); // an edge of a second type in the same batch
      }

      for (int from : new int[] { 0, 2, 4 }) {
        System.out.println(from == 0 ? "Vertex.newEdge():" : from == 2 ? "GraphBatch.newEdge():" : "GraphBatch.newEdge(), batch also holding an F edge:");
        for (Edge e : db.lookupByRID(v[from], true).asVertex().getEdges(Vertex.DIRECTION.OUT, "E")) {
          final StringBuilder sb = new StringBuilder("  ");
          for (String p : e.getPropertyNames()) {
            Object val;
            try {
              val = e.get(p);
            } catch (Exception ex) {
              val = ex.getClass().getSimpleName();
            }
            sb.append(p).append('=').append(val).append(val == null ? "" : " (" + val.getClass().getSimpleName() + ")").append("  ");
          }
          System.out.println(sb);
        }
      }
    }
  }
}
import com.arcadedb.ContextConfiguration;
import com.arcadedb.GlobalConfiguration;
import com.arcadedb.database.*;
import com.arcadedb.graph.*;
import com.arcadedb.server.ArcadeDBServer;

import java.net.URI;
import java.net.http.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class HttpBatchEdgeProperties {
  public static void main(String[] args) throws Exception {
    final ContextConfiguration cfg = new ContextConfiguration();
    cfg.setValue(GlobalConfiguration.SERVER_ROOT_PASSWORD, "repro-password");
    cfg.setValue(GlobalConfiguration.SERVER_ROOT_PATH, args[0]);
    cfg.setValue(GlobalConfiguration.SERVER_DATABASE_DIRECTORY, args[0] + "/databases");
    final ArcadeDBServer server = new ArcadeDBServer(cfg);
    server.start();
    System.out.println("ArcadeDB " + com.arcadedb.Constants.getRawVersion() + " (" + com.arcadedb.Constants.getBuildNumber() + "), Java "
        + System.getProperty("java.version"));
    final Database db = server.getOrCreateDatabase("repro");
    db.command("sql", "CREATE VERTEX TYPE N");
    db.command("sql", "CREATE EDGE TYPE E");
    db.command("sql", "CREATE PROPERTY E.weight INTEGER");
    db.command("sql", "CREATE PROPERTY E.small SHORT");
    db.command("sql", "CREATE PROPERTY E.name STRING (mandatory true)");

    final String body = String.join("\n", //
        "{\"@type\":\"vertex\",\"@class\":\"N\",\"@id\":\"a\",\"id\":1}", //
        "{\"@type\":\"vertex\",\"@class\":\"N\",\"@id\":\"b\",\"id\":2}", //
        "{\"@type\":\"edge\",\"@class\":\"E\",\"@from\":\"a\",\"@to\":\"b\",\"name\":\"x\",\"weight\":null,\"note\":\"hello\"}", //
        "{\"@type\":\"edge\",\"@class\":\"E\",\"@from\":\"a\",\"@to\":\"b\",\"name\":\"y\",\"small\":40000}", //
        "{\"@type\":\"edge\",\"@class\":\"E\",\"@from\":\"a\",\"@to\":\"b\",\"weight\":7}") + "\n";
    final HttpRequest req = HttpRequest.newBuilder(URI.create("http://127.0.0.1:2480/api/v1/batch/repro"))
        .header("Authorization", "Basic " + Base64.getEncoder().encodeToString("root:repro-password".getBytes(StandardCharsets.UTF_8)))
        .header("Content-Type", "application/x-ndjson").POST(HttpRequest.BodyPublishers.ofString(body)).build();
    final HttpResponse<String> resp = HttpClient.newHttpClient().send(req, HttpResponse.BodyHandlers.ofString());
    System.out.println("POST /api/v1/batch/repro -> HTTP " + resp.statusCode());
    System.out.println("request body:");
    System.out.print(body);
    System.out.println("edges stored:");
    db.query("sql", "SELECT FROM E").forEachRemaining(r -> {
      final Edge e = r.getElement().get().asEdge();
      final StringBuilder sb = new StringBuilder("  ");
      for (String p : e.getPropertyNames())
        sb.append(p).append('=').append(e.get(p)).append("  ");
      System.out.println(sb);
    });
    server.stop();
  }
}

Output on main cecb369df9 (the engine jar's build stamp is 04bb03ebec, the newest commit in it that is not a merge), Temurin 25.0.4 with -XX:+UseCompactObjectHeaders. Temurin 21.0.12 printed the same lines apart from the Java version on the first line.

ArcadeDB 26.10.1-SNAPSHOT (04bb03ebec07fce19101595d65ca1e3bdf516755), Java 25.0.4
Vertex.newEdge():
  weight=7 (Integer)  label=null  
  since=null  weight=7 (Integer)  
  weight=null  note=hello (String)  
GraphBatch.newEdge():
  weight=-1 (Integer)  note=hello (String)  
  since=2 (Long)  weight=7 (Integer)  
  weight=7 (Integer)  label=null  
GraphBatch.newEdge(), batch also holding an F edge:
  weight=null  note=hello (String)  
  since=null  weight=7 (Integer)  
  weight=7 (Integer)  label=null  

Logged while the GraphBatch.newEdge(): edges were read:

2026-10-03 08:47:16.520 SEVER [BinarySerializer] Possible corrupted record #4:2050
java.nio.BufferUnderflowException
ArcadeDB 26.10.1-SNAPSHOT (04bb03ebec07fce19101595d65ca1e3bdf516755), Java 25.0.4
POST /api/v1/batch/repro -> HTTP 200
request body:
{"@type":"vertex","@class":"N","@id":"a","id":1}
{"@type":"vertex","@class":"N","@id":"b","id":2}
{"@type":"edge","@class":"E","@from":"a","@to":"b","name":"x","weight":null,"note":"hello"}
{"@type":"edge","@class":"E","@from":"a","@to":"b","name":"y","small":40000}
{"@type":"edge","@class":"E","@from":"a","@to":"b","weight":7}
edges stored:
  name=x  weight=-1  note=hello  
  name=y  small=-25536  
  weight=7  

Versions affected: main cecb369df9 on Temurin 25 and 21, main 417314c18 (2026-09-17), and 26.9.1 print the same lines for both repros, and each logs the same Possible corrupted record #4:2050 line.

Expected: a null for a declared edge property is stored as null, as Vertex.newEdge() and the mixed batch store it, or the property is left out. No record is written with a type tag and no value.

Activity

  1. added
    engine
    server
    severity:critical
    on Oct 3, 2026
  2. added this to the 26.10.1 milestone on Oct 3, 2026
  3. added
    in progress
    on Oct 3, 2026
  4. self-assigned this
    on Oct 3, 2026
  5. added a commit that references this issue on Oct 3, 2026
  6. lvca commented on Oct 3, 2026

    @lvca
    Member

    Fixed in 26.10.1 (#9107). GraphBatch.newEdge() and the HTTP batch endpoint now store a null value for a declared edge property correctly, instead of corrupting the properties that follow it.

    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Oct 3, 2026
  8. tae898 commented on Oct 3, 2026

    @tae898
    ContributorAuthor

    Verified on the merge commit 9c4e264 (it contains #9107 and #9132; engine, server and plugin jars built from it), the repro from the description, on JDK 25 (compact object headers) and JDK 21. The output is the same on both JDKs.

    GraphBatchNullEdgeProperty (the GraphBatch.newEdge() rows, one edge per line):

    edge cecb369 (before) 9c4e264 (after)
    weight null, note "hello" weight=-1 (Integer) note=hello weight=null note=hello
    since null, weight 7 since=2 (Long) weight=7 since=null weight=7
    weight 7, label null weight=7 label=null weight=7 label=null

    The run with the batch also holding an F edge printed a BufferUnderflowException on stderr before and prints nothing there now.

    For the HTTP batch endpoint I ran the HttpBatchEdgeProperties repro as filed, and it now answers HTTP 400 and stores no edge at all (before: HTTP 200 with weight=-1, small=-25536). With the small: 40000 line removed, the server still refuses the batch because the third edge has no name, which is mandatory on E, so I added a name to that line: the batch now stores name=x weight=null note=hello and name=z weight=7 (before: weight=-1).

    Thanks for the fix.

  9. added a commit that references this issue on Oct 4, 2026
  10. added a commit that references this issue on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengineserverseverity:critical

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions