Caused by: java.lang.NullPointerException: corrupted response reader, expected non null value for id
at com.apollographql.apollo.internal.response.RealResponseReader.checkValue(RealResponseReader.java:264)
at com.apollographql.apollo.internal.response.RealResponseReader.readCustomType(RealResponseReader.java:187)
at com.dtcm.dubaichallenge.apollo.fragment.ClassFragment$Mapper.map(ClassFragment.java:387)
at com.dtcm.dubaichallenge.apollo.fragment.FeedItemFragment$Fragments$Mapper.map(FeedItemFragment.java:278)
at com.dtcm.dubaichallenge.apollo.fragment.FeedItemFragment$Mapper$1.read(FeedItemFragment.java:298)
at com.dtcm.dubaichallenge.apollo.fragment.FeedItemFragment$Mapper$1.read(FeedItemFragment.java:295)
at com.apollographql.apollo.internal.response.RealResponseReader.readConditional(RealResponseReader.java:228)
at com.dtcm.dubaichallenge.apollo.fragment.FeedItemFragment$Mapper.map(FeedItemFragment.java:295)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$FeedItem$Fragments$Mapper.map(GetFeedItemsQuery.java:700)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$FeedItem$Mapper$1.read(GetFeedItemsQuery.java:715)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$FeedItem$Mapper$1.read(GetFeedItemsQuery.java:712)
at com.apollographql.apollo.internal.response.RealResponseReader.readConditional(RealResponseReader.java:228)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$FeedItem$Mapper.map(GetFeedItemsQuery.java:712)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$Data$Mapper$1$1.read(GetFeedItemsQuery.java:539)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$Data$Mapper$1$1.read(GetFeedItemsQuery.java:536)
at com.apollographql.apollo.internal.response.RealResponseReader$ListItemReader.readObject(RealResponseReader.java:313)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$Data$Mapper$1.read(GetFeedItemsQuery.java:536)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$Data$Mapper$1.read(GetFeedItemsQuery.java:533)
at com.apollographql.apollo.internal.response.RealResponseReader.readList(RealResponseReader.java:168)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$Data$Mapper.map(GetFeedItemsQuery.java:533)
at com.dtcm.dubaichallenge.apollo.queries.GetFeedItemsQuery$Data$Mapper.map(GetFeedItemsQuery.java:528)
at com.apollographql.apollo.response.OperationResponseParser$1.read(OperationResponseParser.java:96)
at com.apollographql.apollo.internal.json.ResponseJsonStreamReader.nextObject(ResponseJsonStreamReader.java:86)
at com.apollographql.apollo.response.OperationResponseParser.parse(OperationResponseParser.java:91)
at com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor.parse(ApolloParseInterceptor.java:87)
at com.apollographql.apollo.internal.interceptor.ApolloParseInterceptor$1.onResponse(ApolloParseInterceptor.java:53)聽
at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$2.onResponse(ApolloServerInterceptor.java:125)聽
at okhttp3.RealCall$AsyncCall.run(RealCall.kt:138)聽
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)聽
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)聽
at java.lang.Thread.run(Thread.java:764)
meet the same problem.
Could you pls send me an example of your query and response?
It seems that for some reason the field id is declared as non-optional but in response it's null?
private void checkValue(ResponseField field, Object value) {
if (!field.optional() && value == null) {
throw new NullPointerException("corrupted response reader, expected non null value for " + field.fieldName());
}
}
I got the same problem when upgrading from 1.0.1 to 1.0.2 on a specific query.
After debuging I had a duplicate node in our graphql query, but it works on our graphql explorer...
I had this :
fragment MajorElement on ThreadElement {
id
type
threadable {
id
}
...ElementMiscellaneous
}
fragment ElementMiscellaneous on ThreadElementMiscellaneous {
miscellaneousType
threadable {
...ThreadableInfo
}
}
fragment ThreadableInfo on Threadable {
user {
firstName
phone
}
}
As a quick workaround we decide to use this query :
fragment MajorElement on ThreadElement {
id
type
...ElementMiscellaneous
}
fragment ElementMiscellaneous on ThreadElementMiscellaneous {
miscellaneousType
threadable {
...ThreadableInfo
}
}
fragment ThreadableInfo on Threadable {
id
user {
firstName
phone
}
}
As we can see we removed the threadable { id } and move the id in the fragment ThreadableInfo.
We have rollback to 1.0.1.
We're encountering the same issue. v1.0.1 works great, but every subsequent version has NPEs that match what others have said. I unfortunately can't provide a full schema or query, but here's a summary that _may_ help:
query DemoQuery($thingId: ID!) {
node(id: $thingId) {
...DemoFragment
}
}
fragment DemoFragment on DemoObject {
id
to {
id
name
...ProblematicDemoFragment
}
}
fragment ProblematicDemoFragment on SubTypeA {
image
}
The generated code for this assumes that all of to's fragments will be of type ProblematicDemoFragment (SubTypeA), but in reality they could also be SubTypeB. When SubTypeB objects come down, which do not have an image field, NPEs happen.
It might be a duplication of https://github.com/apollographql/apollo-android/issues/1584 that was fixed in latest snapshot version.
We also experience the same issue after migrating to the version 1.0.2 and for us it seems the issue is caused by the following change: https://github.com/apollographql/apollo-android/pull/1410.
We have following query:
query SingleBlockQuery($blockId: String!, $offset: Int!, $first: Int!) {
block(id: $blockId) {
id
assets(offset: $offset, first: $first) {
...MovieCoverFragment
...SeriesCoverFragment
...BrandCoverFragment
...EpisodeCoverFragment
...EpgFragment
...CompilationCoverFragment
}
...
On version 1.0.1 Appolo generates following code for fragments mapper:
@Override
public @NotNull Fragments map(ResponseReader reader, @NotNull String conditionalType) {
MovieCoverFragment movieCoverFragment = null;
SeriesCoverFragment seriesCoverFragment = null;
BrandCoverFragment brandCoverFragment = null;
EpisodeCoverFragment episodeCoverFragment = null;
EpgFragment epgFragment = null;
CompilationCoverFragment compilationCoverFragment = null;
if (MovieCoverFragment.POSSIBLE_TYPES.contains(conditionalType)) {
movieCoverFragment = movieCoverFragmentFieldMapper.map(reader);
}
if (SeriesCoverFragment.POSSIBLE_TYPES.contains(conditionalType)) {
seriesCoverFragment = seriesCoverFragmentFieldMapper.map(reader);
}
if (BrandCoverFragment.POSSIBLE_TYPES.contains(conditionalType)) {
brandCoverFragment = brandCoverFragmentFieldMapper.map(reader);
}
if (EpisodeCoverFragment.POSSIBLE_TYPES.contains(conditionalType)) {
episodeCoverFragment = episodeCoverFragmentFieldMapper.map(reader);
}
if (EpgFragment.POSSIBLE_TYPES.contains(conditionalType)) {
epgFragment = epgFragmentFieldMapper.map(reader);
}
if (CompilationCoverFragment.POSSIBLE_TYPES.contains(conditionalType)) {
compilationCoverFragment = compilationCoverFragmentFieldMapper.map(reader);
}
return new Fragments(movieCoverFragment, seriesCoverFragment, brandCoverFragment, episodeCoverFragment, epgFragment, compilationCoverFragment);
}
But Apollo ver 1.0.2 generates following code:
@Override
public @NotNull Fragments map(ResponseReader reader, @NotNull String conditionalType) {
MovieCoverFragment movieCoverFragment = movieCoverFragmentFieldMapper.map(reader);
SeriesCoverFragment seriesCoverFragment = seriesCoverFragmentFieldMapper.map(reader);
BrandCoverFragment brandCoverFragment = brandCoverFragmentFieldMapper.map(reader);
EpisodeCoverFragment episodeCoverFragment = episodeCoverFragmentFieldMapper.map(reader);
EpgFragment epgFragment = epgFragmentFieldMapper.map(reader);
CompilationCoverFragment compilationCoverFragment = compilationCoverFragmentFieldMapper.map(reader);
return new Fragments(movieCoverFragment, seriesCoverFragment, brandCoverFragment, episodeCoverFragment, epgFragment, compilationCoverFragment);
}
I debugged the code and observed that with ver 1.0.2 we fail because we are trying to call brandCoverFragmentFieldMapper.map(reader) for the data which corresponds to SeriesCoverFragment. As SeriesCoverFragment doesn't have all the properties which are required by BrandCoverFragment we are getting the same aforementioned NPE exception.
For version 1.0.1 it does work because BrandCoverFragment.POSSIBLE_TYPES.contains(conditionalType) gives false for SeriesCoverFragment.
Could some of you folks try latest snapshot to see if this issue fixed?
I'm blocked from testing the latest snapshot by #1582, so I can't help debug at the moment. I've tried adding apollographql.useExperimentalCodegen=false to my gradle.properties, but it doesn't seem to have an effect.
Update: tweaked a seemingly endless number of graphql files until I got the project to build. Can confirm the latest snapshot fixes the NPE issue that's existed since 1.0.2.
Alright, closing for now. I hope we will get new release this week.
Most helpful comment
meet the same problem.