-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes GH-2013 by traversing parents until sourceString is found #2014
Merged
abrokenjester
merged 1 commit into
master
from
issues/#2013-NPE-service-multiple-update-expressions
Mar 20, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...rql/src/test/java/org/eclipse/rdf4j/query/parser/sparql/TestServiceUpdateExprBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2020 Eclipse RDF4J contributors. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.query.parser.sparql; | ||
|
||
import org.eclipse.rdf4j.query.algebra.Service; | ||
import org.eclipse.rdf4j.query.parser.ParsedUpdate; | ||
import org.junit.Test; | ||
|
||
public class TestServiceUpdateExprBuilder { | ||
|
||
/** | ||
* The test reproduces a {@link NullPointerException} that is thrown when parsing an update with several update | ||
* expressions and one of these contain {@link Service} operator The NPE is thrown because the sourceString is set | ||
* to the outermost operation container | ||
*/ | ||
@Test | ||
public void testServiceWithMultipleUpdateExpr() { | ||
SPARQLParser parser = new SPARQLParser(); | ||
String updateStr = "PREFIX family: <http://examples.ontotext.com/family#>\n" + | ||
"DROP ALL ;\n" + | ||
"INSERT {\n" + | ||
" family:Alice family:knows family:Bob .\n" + | ||
"}\n" + | ||
"WHERE {\n" + | ||
" SERVICE <repository:1> {\n" + | ||
" family:Alice family:knows family:Bob .\n" + | ||
" }\n" + | ||
"}"; | ||
// should not throw NPE, but prior to 3.1.3 it does | ||
parser.parseUpdate(updateStr, null); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if maybe there could be a null check here, so that any exception is thrown when looking for the source string instead of when using the resulting string. Maybe
return Objects.requireNonNull(sourceString);
Unless of course there is a case where returning null from getSourceString() is acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought of that for a while, but decided that if we did not found the
sourceString
at this point, something else was really messed up, so throwing a custom exception early, would not help much here since we do not have a resonable alternative to continue processing update further - a NPE will still be thrown in the code that uses it ...