Skip to content

Datomic.qseq throws NullPointerException instead of returning an empty result. #5

@Acuadragon100

Description

@Acuadragon100

It seems Datomic.qseq always throws a NullPointerException when the query result is empty.
I'm using com.datomic:local:1.0.285 and org.scalamolecule:datomic-client-api-java-scala_2.13:1.0.3.

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "clojure.lang.ASeq.stream()" because the return value of "datomicClient.Invoke$.qseq(java.util.Map)" is null
	at datomicJava.client.api.sync.Datomic$.qseq(Datomic.scala:102)
	at datomicJava.client.api.sync.Datomic$.qseq(Datomic.scala:110)
	at datomicJava.client.api.sync.Datomic$.qseq(Datomic.scala:107)
	at datomicJava.client.api.sync.Datomic.qseq(Datomic.scala)
	at org.example.Main.main(Main.java:51)

Workaround for users:
Just put a try catch around it, and treat a caught NullPointerException as an empty result.

To reproduce:

package org.example;

import datomicJava.client.api.sync.Datomic;

import java.nio.file.Path;
import java.util.List;
import java.util.Map;

import static clojure.java.api.Clojure.read;

public class Main {

	public static void main(String[] args) {
		String test = "test";
		var client = Datomic.clientDevLocal(test, Path.of(".").toAbsolutePath().toString());
		boolean create = false;
		if (!client.listDatabases().contains(test)) {
			client.createDatabase(test);
			create = true;
		}
		var connection = client.connect(test);
		final Object FIND = read(":find");
		final Object WHERE = read(":where");
		final Object TEST_IDENT = read(":test/testIdent");
		if (create) {
			connection.transact(
				List.of(
					Map.of(
						read(":db/ident"), TEST_IDENT,
						read(":db/valueType"), read(":db.type/string"),
						read(":db/unique"), read(":db.unique/identity"),
						read(":db/cardinality"), read(":db.cardinality/one")
					)
				)
			);
		}

		var b = read("?b");
		var EMPTY = read("_");


		var res = Datomic.q(
			List.of(
				FIND, b, WHERE,
				List.of(EMPTY, TEST_IDENT, b)
			),
			connection.db()
		);
		assert res.isEmpty();

		var seq = Datomic.qseq( //NullPointerException thrown here.
			List.of(
				FIND, b, WHERE,
				List.of(EMPTY, TEST_IDENT, b)
			),
			connection.db()
		);
		assert seq.findAny().isEmpty();

		System.exit(0);
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions