1616
1717package org .springframework .graphql .client ;
1818
19- import java .math .BigInteger ;
2019import java .util .Collections ;
2120import java .util .List ;
2221import java .util .Map ;
23- import java .util .Objects ;
2422import java .util .stream .Collectors ;
2523
2624import graphql .ErrorClassification ;
@@ -125,29 +123,28 @@ private static final class MapResponseError implements ResponseError {
125123 MapResponseError (Map <String , Object > errorMap ) {
126124 Assert .notNull (errorMap , "'errorMap' is required" );
127125 this .errorMap = errorMap ;
128- this .locations = initLocations (errorMap );
126+ this .locations = initSourceLocations (errorMap );
129127 this .path = initPath (errorMap );
130128 }
131129
132130 @ SuppressWarnings ("unchecked" )
133- private static List <SourceLocation > initLocations (Map <String , Object > errorMap ) {
134- return (( List <Map <String , Object >>) errorMap .getOrDefault ("locations" , Collections . emptyList ())). stream ()
135- . map ( map -> new SourceLocation (
136- objectAsInt ( map . get ( "line" )),
137- objectAsInt ( map . get ( "column" )),
138- Objects . toString ( map . get ( "sourceName" ) )
139- ))
131+ private static List <SourceLocation > initSourceLocations (Map <String , Object > errorMap ) {
132+ List < Map < String , Object >> locations = ( List <Map <String , Object >>) errorMap .get ("locations" );
133+ if ( locations == null ) {
134+ return Collections . emptyList ();
135+ }
136+ return locations . stream ( )
137+ . map ( m -> new SourceLocation ( getInt ( m , "line" ), getInt ( m , "column" ), ( String ) m . get ( "sourceName" ) ))
140138 .collect (Collectors .toList ());
141139 }
142140
143- private static int objectAsInt (Object value ) {
144-
145- if (value instanceof BigInteger bigInteger ) {
146- return bigInteger .intValue ();
147- } else if (value instanceof Number number ) {
141+ private static int getInt (Map <String , Object > map , String key ) {
142+ if (map .get (key ) instanceof Number number ) {
148143 return number .intValue ();
149- } else {
150- return -1 ;
144+ }
145+ else {
146+ throw new IllegalArgumentException (
147+ "Expected integer value: " + ObjectUtils .nullSafeClassName (map .get (key )));
151148 }
152149 }
153150
@@ -162,6 +159,7 @@ private static String initPath(Map<String, Object> errorMap) {
162159 (s , s2 ) -> null );
163160 }
164161
162+
165163 @ Override
166164 @ Nullable
167165 public String getMessage () {
0 commit comments