NPE in CacheProvider caused by adding default values for variables
See original GitHub issueHi @bbakerman @andimarek,
I implemented a CacheProvider:
public class CacheProvider implements PreparsedDocumentProvider {
@Resource
private Cache<String, PreparsedDocumentEntry> cache;
@Override
public PreparsedDocumentEntry getDocument(final ExecutionInput executionInput,
final Function<ExecutionInput, PreparsedDocumentEntry> computeFunction) {
final Function<String, PreparsedDocumentEntry> mapCompute = key -> {
try {
return computeFunction.apply(executionInput);
} catch (Exception e) {
throw new IllegalArgumentException(String.format("Failed to compute cache key for query: %s . variables: %s",
executionInput.getQuery(), executionInput.getVariables()));
}
};
return cache.get(executionInput.getQuery(), mapCompute);
}
}
I got a NPE when I call computeFunction.apply(executionInput)
with this kind of queries:
query search($texte: String = "", $includetest: Boolean = true){
search(query: $texte) {
test @include(if: $includetest){
...testFragment
}
}
}
Variables:
{
"texte": "work"
}
If I add includetest
in my variables, it works. Is it the expected behavior ?
Default variables
Default values can also be assigned to the variables in the query by adding the default value after the type declaration.
query HeroNameAndFriends($episode: Episode = JEDI) {
hero(episode: $episode) {
name
friends {
name
}
}
}
When default values are provided for all variables, you can call the query without passing any variables. If any variables are passed as part of the variables dictionary, they will override the defaults.
Infos:
<caffeine.version>2.8.6</caffeine.version>
<graphql-java.version>15.0</graphql-java.version>
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
java - Can I give a default value like this to avoid null pointer ...
None of the code in your sample would cause an NPE, no matter if you initialise the attribute owner with the empty String,...
Read more >How to deal with NullPointerException in Java with Examples
In Java reference variable points to object created in heap but when you create a reference variable of type object by default its...
Read more >Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Default value for a database column; 4.5. ... HQL syntax for INSERT; 12.3.3. ... the hibernate.implicit_naming_strategy configuration setting which accepts:.
Read more >Does not evaluate Terraform null variable default values #651
Null in Terraform is the equivalent of having the attribute being set to that value as absent. I believe this is causing false...
Read more >How to set a default value to a Variable by judgin... - ServiceNow
Solved: We make our support page by the Record Producer. I want to set a different default value to a Variable per URL-parameter....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
eg
This type of code.
The work around here is to define the conditional variables explicitly until this bug is fixed when using these instrumentions
I am able to reproduce this a bug
It’s caused by ConditionalNodes being invoked BUT the variable coercer has not run yet to default the variables (which happens after parse/validate.
Both of these instrumentions call
we have to move the variable coercing code into this so that we can do the defaulting as required