22
33import java .io .IOException ;
44import java .lang .annotation .Annotation ;
5- import java .lang .reflect .Array ;
65import java .lang .reflect .Constructor ;
76import java .lang .reflect .InvocationTargetException ;
87import java .lang .reflect .ParameterizedType ;
@@ -74,10 +73,10 @@ public <T> T decode(int offset, Class<T> cls) throws IOException {
7473 }
7574
7675 this .buffer .position (offset );
77- return cls .cast (decode (cls , null ));
76+ return cls .cast (decode (cls , null ). getValue () );
7877 }
7978
80- private <T > Object decode (CacheKey <T > key ) throws IOException {
79+ private <T > DecodedValue decode (CacheKey <T > key ) throws IOException {
8180 int offset = key .getOffset ();
8281 if (offset >= this .buffer .capacity ()) {
8382 throw new InvalidDatabaseException (
@@ -90,7 +89,7 @@ private <T> Object decode(CacheKey<T> key) throws IOException {
9089 return decode (cls , key .getType ());
9190 }
9291
93- private <T > Object decode (Class <T > cls , java .lang .reflect .Type genericType )
92+ private <T > DecodedValue decode (Class <T > cls , java .lang .reflect .Type genericType )
9493 throws IOException {
9594 int ctrlByte = 0xFF & this .buffer .get ();
9695
@@ -107,14 +106,14 @@ private <T> Object decode(Class<T> cls, java.lang.reflect.Type genericType)
107106
108107 // for unit testing
109108 if (this .POINTER_TEST_HACK ) {
110- return pointer ;
109+ return new DecodedValue ( pointer ) ;
111110 }
112111
113112 int targetOffset = (int ) pointer ;
114113 int position = buffer .position ();
115114
116115 CacheKey key = new CacheKey (targetOffset , cls , genericType );
117- Object o = decode (key );
116+ DecodedValue o = cache . get (key , cacheLoader );
118117
119118 buffer .position (position );
120119 return o ;
@@ -149,7 +148,7 @@ private <T> Object decode(Class<T> cls, java.lang.reflect.Type genericType)
149148 }
150149 }
151150
152- return this .decodeByType (type , size , cls , genericType );
151+ return new DecodedValue ( this .decodeByType (type , size , cls , genericType ) );
153152 }
154153
155154 private <T > Object decodeByType (
@@ -284,7 +283,7 @@ private <T, V> List<V> decodeArray(
284283 Class <V > elementClass
285284 ) throws IOException {
286285 if (!List .class .isAssignableFrom (cls ) && !cls .equals (Object .class )) {
287- throw new DeserializationException ();
286+ throw new DeserializationException ("Unable to deserialize an array into an " + cls );
288287 }
289288
290289 List <V > array ;
@@ -310,7 +309,7 @@ private <T, V> List<V> decodeArray(
310309 }
311310
312311 for (int i = 0 ; i < size ; i ++) {
313- Object e = this .decode (elementClass , null );
312+ Object e = this .decode (elementClass , null ). getValue () ;
314313 array .add (elementClass .cast (e ));
315314 }
316315
@@ -371,8 +370,8 @@ private <T, V> Map<String, V> decodeMapIntoMap(
371370 }
372371
373372 for (int i = 0 ; i < size ; i ++) {
374- String key = (String ) this .decode (String .class , null );
375- Object value = this .decode (valueClass , null );
373+ String key = (String ) this .decode (String .class , null ). getValue () ;
374+ Object value = this .decode (valueClass , null ). getValue () ;
376375 map .put (key , valueClass .cast (value ));
377376 }
378377
@@ -418,7 +417,7 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
418417
419418 Object [] parameters = new Object [parameterTypes .length ];
420419 for (int i = 0 ; i < size ; i ++) {
421- String key = (String ) this .decode (String .class , null );
420+ String key = (String ) this .decode (String .class , null ). getValue () ;
422421
423422 Integer parameterIndex = parameterIndexes .get (key );
424423 if (parameterIndex == null ) {
@@ -430,7 +429,7 @@ private <T> Object decodeMapIntoObject(int size, Class<T> cls)
430429 parameters [parameterIndex ] = this .decode (
431430 parameterTypes [parameterIndex ],
432431 parameterGenericTypes [parameterIndex ]
433- );
432+ ). getValue () ;
434433 }
435434
436435 try {
0 commit comments