miselico / sparql_query_log_analysis

1 stars 0 forks source link

java.lang.NullPointerException for Query q = QueryFactory.create() #1

Open marmhm opened 2 years ago

marmhm commented 2 years ago

Hi,

Running this code:

import org.apache.jena.query.QueryFactory;
Query q = QueryFactory.create("SELECT * WHERE { <http://test.com/subject> ?p \"Hello\" . }");

Getting this error stack trace:

java.lang.NullPointerException
        at org.apache.jena.query.ARQ.isTrue(ARQ.java:650)
        at org.apache.jena.sparql.lang.ParserBase.<init>(ParserBase.java:312)
        at org.apache.jena.sparql.lang.SPARQLParserBase.<init>(SPARQLParserBase.java:43)
        at org.apache.jena.sparql.lang.arq.ARQParserBase.<init>(ARQParserBase.java:35)
        at org.apache.jena.sparql.lang.arq.ARQParser.<init>(ARQParser.java:7641)
        at org.apache.jena.sparql.lang.ParserARQ.perform(ParserARQ.java:91)
        at org.apache.jena.sparql.lang.ParserARQ.parse$(ParserARQ.java:52)
        at org.apache.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:34)
        at org.apache.jena.query.QueryFactory.parse(QueryFactory.java:151)
        at org.apache.jena.query.QueryFactory.create(QueryFactory.java:83)
        at org.apache.jena.query.QueryFactory.create(QueryFactory.java:56)
        at org.apache.jena.query.QueryFactory.create(QueryFactory.java:44)
        at nl.cochez.query_processing.metadata.MainStatistics.main(MainStatistics.java:129)

Using Java 11 and maven 3.8.5 And this properties/dependency in pom.xml:

   <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <!-- <maven.compiler.release>15</maven.compiler.release> -->
    </properties>

        <dependency>
            <groupId>org.apache.jena</groupId>
            <artifactId>apache-jena-libs</artifactId>
            <version>3.17.0</version>
            <type>pom</type>
        </dependency>
miselico commented 2 years ago

Can you try with (notice the <> around the URL): Query q = QueryFactory.create("SELECT * WHERE { <http://test.com/subject> ?p "Hello" . }");

marmhm commented 2 years ago

Still getting the same error. I am running 'MainStatistics.java' line 124: Query q = QueryFactory.create(query) raise this error

miselico commented 2 years ago

Can you try creating a new class with this method? This runs fine for me. I changed my jena version to the one you are using.

import org.apache.jena.query.Query;
import org.apache.jena.query.QueryFactory;

public class TestingSomething {
    public static void main(String[] args) {
        Query q = QueryFactory.create("SELECT * WHERE { <http://test.com/subject> ?p \"Hello\" }");
        System.out.println(q);
    }
}
miselico commented 2 years ago

If that gives the same error, can you add the following call at the start of the code:

org.apache.jena.query.ARQ.init();
marmhm commented 2 years ago

Thanks, after adding the following line it is working.

org.apache.jena.query.ARQ.init();