• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wuwen5 / hessian / 17803828826

15 Sep 2025 01:09AM UTC coverage: 69.283% (+0.2%) from 69.121%
17803828826

push

github

web-flow
perf(calendar): performance optimization of calendar serialization and deserialization (#44)

1830 of 2837 branches covered (64.5%)

Branch coverage included in aggregate %.

4226 of 5904 relevant lines covered (71.58%)

3.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.88
hessian2-codec/src/main/java/io/github/wuwen5/hessian/io/SerializerFactory.java
1
/*
2
 * Copyright (c) 2001-2008 Caucho Technology, Inc.  All rights reserved.
3
 *
4
 * The Apache Software License, Version 1.1
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 *
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in
15
 *    the documentation and/or other materials provided with the
16
 *    distribution.
17
 *
18
 * 3. The end-user documentation included with the redistribution, if
19
 *    any, must include the following acknowlegement:
20
 *       "This product includes software developed by the
21
 *        Caucho Technology (http://www.caucho.com/)."
22
 *    Alternately, this acknowlegement may appear in the software itself,
23
 *    if and wherever such third-party acknowlegements normally appear.
24
 *
25
 * 4. The names "Burlap", "Resin", and "Caucho" must not be used to
26
 *    endorse or promote products derived from this software without prior
27
 *    written permission. For written permission, please contact
28
 *    info@caucho.com.
29
 *
30
 * 5. Products derived from this software may not be called "Resin"
31
 *    nor may "Resin" appear in their names without prior written
32
 *    permission of Caucho Technology.
33
 *
34
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37
 * DISCLAIMED.  IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
38
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
40
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
44
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
 *
46
 * @author Scott Ferguson
47
 */
48

49
package io.github.wuwen5.hessian.io;
50

51
import com.caucho.hessian.io.HessianRemoteObject;
52
import java.io.IOException;
53
import java.io.InputStream;
54
import java.io.Serializable;
55
import java.lang.annotation.Annotation;
56
import java.lang.ref.SoftReference;
57
import java.lang.ref.WeakReference;
58
import java.net.InetAddress;
59
import java.util.ArrayList;
60
import java.util.Calendar;
61
import java.util.Collection;
62
import java.util.Enumeration;
63
import java.util.HashMap;
64
import java.util.Iterator;
65
import java.util.List;
66
import java.util.Map;
67
import java.util.WeakHashMap;
68
import java.util.concurrent.ConcurrentHashMap;
69
import java.util.concurrent.ConcurrentMap;
70
import java.util.logging.Level;
71
import java.util.logging.Logger;
72
import lombok.SneakyThrows;
73

74
/**
75
 * Factory for returning serialization methods.
76
 */
77
public class SerializerFactory extends AbstractSerializerFactory {
78
    private static final Logger log = Logger.getLogger(SerializerFactory.class.getName());
4✔
79

80
    private static final ClassLoader SYSTEM_CLASS_LOADER;
81

82
    private static final Map<String, Deserializer> STATIC_TYPE_MAP;
83

84
    private static final WeakHashMap<ClassLoader, SoftReference<SerializerFactory>> DEFAULT_FACTORY_REF_MAP =
4✔
85
            new WeakHashMap<>();
86

87
    private final ContextSerializerFactory contextFactory;
88
    private final WeakReference<ClassLoader> loaderRef;
89

90
    protected Serializer defaultSerializer;
91

92
    /**
93
     * Additional factories
94
     */
95
    protected List<AbstractSerializerFactory> factories = new ArrayList<>();
5✔
96

97
    protected CollectionSerializer collectionSerializer;
98
    protected MapSerializer mapSerializer;
99

100
    private Deserializer hashMapDeserializer;
101
    private Deserializer arrayListDeserializer;
102
    private final ConcurrentMap<Class<?>, Serializer> cachedSerializerMap = new ConcurrentHashMap<>(8);
6✔
103
    private final ConcurrentMap<Class<?>, Deserializer> cachedDeserializerMap = new ConcurrentHashMap<>(8);
6✔
104
    private final ConcurrentMap<String, Deserializer> cachedTypeDeserializerMap = new ConcurrentHashMap<>();
5✔
105

106
    private boolean isAllowNonSerializable;
107
    private final boolean isEnableUnsafeSerializer = (UnsafeSerializer.isEnabled() && UnsafeDeserializer.isEnabled());
9!
108

109
    private final FieldDeserializer2Factory fieldDeserializer2Factory;
110

111
    private ClassFactory classFactory;
112

113
    public SerializerFactory() {
114
        this(Thread.currentThread().getContextClassLoader());
4✔
115
    }
1✔
116

117
    public SerializerFactory(ClassLoader loader) {
2✔
118
        loaderRef = new WeakReference<>(loader);
6✔
119

120
        contextFactory = ContextSerializerFactory.create(loader);
4✔
121

122
        if (isEnableUnsafeSerializer) {
3✔
123
            fieldDeserializer2Factory = new FieldDeserializer2FactoryUnsafe();
6✔
124
        } else {
125
            fieldDeserializer2Factory = new FieldDeserializer2Factory();
5✔
126
        }
127
    }
1✔
128

129
    public static SerializerFactory createDefault() {
130
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
3✔
131

132
        synchronized (DEFAULT_FACTORY_REF_MAP) {
4✔
133
            SoftReference<SerializerFactory> factoryRef = DEFAULT_FACTORY_REF_MAP.get(loader);
5✔
134

135
            SerializerFactory factory = null;
2✔
136

137
            if (factoryRef != null) {
2✔
138
                factory = factoryRef.get();
4✔
139
            }
140

141
            if (factory == null) {
2✔
142
                factory = new SerializerFactory();
4✔
143

144
                factoryRef = new SoftReference<>(factory);
5✔
145

146
                DEFAULT_FACTORY_REF_MAP.put(loader, factoryRef);
5✔
147
            }
148

149
            return factory;
4✔
150
        }
151
    }
152

153
    public ClassLoader getClassLoader() {
154
        return loaderRef.get();
5✔
155
    }
156

157
    /**
158
     * Set true if the collection serializer should send the java type.
159
     */
160
    public void setSendCollectionType(boolean isSendType) {
161
        if (collectionSerializer == null) {
×
162
            collectionSerializer = new CollectionSerializer();
×
163
        }
164

165
        collectionSerializer.setSendJavaType(isSendType);
×
166

167
        if (mapSerializer == null) {
×
168
            mapSerializer = new MapSerializer();
×
169
        }
170

171
        mapSerializer.setSendJavaType(isSendType);
×
172
    }
×
173

174
    /**
175
     * Adds a factory.
176
     */
177
    public void addFactory(AbstractSerializerFactory factory) {
178
        factories.add(factory);
×
179
    }
×
180

181
    /**
182
     * If true, non-serializable objects are allowed.
183
     */
184
    public void setAllowNonSerializable(boolean allow) {
185
        isAllowNonSerializable = allow;
×
186
    }
×
187

188
    /**
189
     * If true, non-serializable objects are allowed.
190
     */
191
    public boolean isAllowNonSerializable() {
192
        return isAllowNonSerializable;
×
193
    }
194

195
    /**
196
     * Returns the serializer for a class.
197
     *
198
     * @param cl the class of the object that needs to be serialized.
199
     *
200
     * @return a serializer object for the serialization.
201
     */
202
    public Serializer getObjectSerializer(Class<?> cl) throws HessianProtocolException {
203
        Serializer serializer = getSerializer(cl);
4✔
204

205
        if (serializer instanceof ObjectSerializer) {
3✔
206
            return ((ObjectSerializer) serializer).getObjectSerializer();
4✔
207
        } else {
208
            return serializer;
2✔
209
        }
210
    }
211

212
    public Class<?> loadSerializedClass(String className) throws ClassNotFoundException {
213
        return getClassFactory().load(className);
5✔
214
    }
215

216
    public ClassFactory getClassFactory() {
217
        synchronized (this) {
4✔
218
            if (classFactory == null) {
3✔
219
                classFactory = new ClassFactory(getClassLoader());
7✔
220
            }
221

222
            return classFactory;
5✔
223
        }
224
    }
225

226
    public FieldDeserializer2Factory getFieldDeserializerFactory() {
227
        return fieldDeserializer2Factory;
×
228
    }
229

230
    /**
231
     * Returns the serializer for a class.
232
     *
233
     * @param cl the class of the object that needs to be serialized.
234
     *
235
     * @return a serializer object for the serialization.
236
     */
237
    @Override
238
    public Serializer getSerializer(Class<?> cl) throws HessianProtocolException {
239
        Serializer serializer = cachedSerializerMap.get(cl);
6✔
240

241
        if (serializer != null) {
2✔
242
            return serializer;
2✔
243
        }
244

245
        return cachedSerializerMap.computeIfAbsent(cl, this::loadSerializer);
8✔
246
    }
247

248
    @SneakyThrows
3✔
249
    protected Serializer loadSerializer(Class<?> cl) {
250
        Serializer serializer;
251

252
        for (int i = 0; factories != null && i < factories.size(); i++) {
10!
253
            AbstractSerializerFactory factory = factories.get(i);
×
254

255
            serializer = factory.getSerializer(cl);
×
256

257
            if (serializer != null) {
×
258
                return serializer;
×
259
            }
260
        }
261

262
        serializer = contextFactory.getSerializer(cl.getName());
6✔
263

264
        if (serializer != null) {
2✔
265
            return serializer;
2✔
266
        }
267

268
        ClassLoader loader = cl.getClassLoader();
3✔
269

270
        if (loader == null) {
2✔
271
            loader = SYSTEM_CLASS_LOADER;
2✔
272
        }
273

274
        ContextSerializerFactory factory = ContextSerializerFactory.create(loader);
3✔
275

276
        serializer = factory.getCustomSerializer(cl);
4✔
277

278
        if (serializer != null) {
2!
279
            return serializer;
×
280
        }
281

282
        if (HessianRemoteObject.class.isAssignableFrom(cl)) {
4!
283
            return new RemoteSerializer();
×
284
        } // TODO
285
        //    else if (BurlapRemoteObject.class.isAssignableFrom(cl)) {
286
        //      return new RemoteSerializer();
287
        //    }
288
        else if (InetAddress.class.isAssignableFrom(cl)) {
4✔
289
            return InetAddressSerializer.create();
2✔
290
        } else if (JavaSerializer.getWriteReplace(cl) != null) {
3✔
291
            Serializer baseSerializer = getDefaultSerializer(cl);
4✔
292

293
            return new WriteReplaceSerializer(cl, getClassLoader(), baseSerializer);
8✔
294
        } else if (Map.class.isAssignableFrom(cl)) {
4✔
295
            if (mapSerializer == null) {
3✔
296
                mapSerializer = new MapSerializer();
5✔
297
            }
298

299
            return mapSerializer;
3✔
300
        } else if (Collection.class.isAssignableFrom(cl)) {
4✔
301
            if (collectionSerializer == null) {
3✔
302
                collectionSerializer = new CollectionSerializer();
5✔
303
            }
304

305
            return collectionSerializer;
3✔
306
        } else if (cl.isArray()) {
3✔
307
            return new ArraySerializer();
4✔
308
        } else if (Throwable.class.isAssignableFrom(cl)) {
4✔
309
            return new ThrowableSerializer(getDefaultSerializer(cl));
7✔
310
        } else if (InputStream.class.isAssignableFrom(cl)) {
4!
311
            return new InputStreamSerializer();
×
312
        } else if (Iterator.class.isAssignableFrom(cl)) {
4!
313
            return IteratorSerializer.create();
×
314
        } else if (Calendar.class.isAssignableFrom(cl)) {
4✔
315
            return CalendarSerializer.SER;
2✔
316
        } else if (Enumeration.class.isAssignableFrom(cl)) {
4✔
317
            return EnumerationSerializer.create();
2✔
318
        } else if (Enum.class.isAssignableFrom(cl)) {
4✔
319
            return new EnumSerializer(cl);
5✔
320
        } else if (Annotation.class.isAssignableFrom(cl)) {
4✔
321
            return new AnnotationSerializer(cl);
5✔
322
        }
323

324
        return getDefaultSerializer(cl);
4✔
325
    }
326

327
    /**
328
     * Returns the default serializer for a class that isn't matched
329
     * directly.  Application can override this method to produce
330
     * bean-style serialization instead of field serialization.
331
     *
332
     * @param cl the class of the object that needs to be serialized.
333
     *
334
     * @return a serializer object for the serialization.
335
     */
336
    protected Serializer getDefaultSerializer(Class<?> cl) {
337
        if (defaultSerializer != null) {
3!
338
            return defaultSerializer;
×
339
        }
340

341
        if (!Serializable.class.isAssignableFrom(cl) && !isAllowNonSerializable) {
7!
342
            throw new IllegalStateException(
3✔
343
                    "Serialized class " + cl.getName() + " must implement java.io.Serializable");
4✔
344
        }
345

346
        if (isEnableUnsafeSerializer && JavaSerializer.getWriteReplace(cl) == null) {
6✔
347
            return UnsafeSerializer.create(cl);
3✔
348
        } else {
349
            return JavaSerializer.create(cl);
3✔
350
        }
351
    }
352

353
    /**
354
     * Returns the deserializer for a class.
355
     *
356
     * @param cl the class of the object that needs to be deserialized.
357
     *
358
     * @return a deserializer object for the serialization.
359
     */
360
    @Override
361
    public Deserializer getDeserializer(Class<?> cl) throws HessianProtocolException {
362
        Deserializer deserializer = cachedDeserializerMap.get(cl);
6✔
363

364
        if (deserializer != null) {
2✔
365
            return deserializer;
2✔
366
        }
367

368
        return cachedDeserializerMap.computeIfAbsent(cl, this::loadDeserializer);
8✔
369
    }
370

371
    @SneakyThrows
3✔
372
    protected Deserializer loadDeserializer(Class<?> cl) {
373
        Deserializer deserializer = null;
2✔
374

375
        for (int i = 0; deserializer == null && factories != null && i < factories.size(); i++) {
12!
376
            AbstractSerializerFactory factory = factories.get(i);
×
377

378
            deserializer = factory.getDeserializer(cl);
×
379
        }
380

381
        if (deserializer != null) {
2!
382
            return deserializer;
×
383
        }
384

385
        // XXX: need test
386
        deserializer = contextFactory.getDeserializer(cl.getName());
6✔
387

388
        if (deserializer != null) {
2✔
389
            return deserializer;
2✔
390
        }
391

392
        ContextSerializerFactory factory;
393

394
        if (cl.getClassLoader() != null) {
3✔
395
            factory = ContextSerializerFactory.create(cl.getClassLoader());
5✔
396
        } else {
397
            factory = ContextSerializerFactory.create(SYSTEM_CLASS_LOADER);
3✔
398
        }
399

400
        deserializer = factory.getDeserializer(cl.getName());
5✔
401

402
        if (deserializer != null) {
2!
403
            return deserializer;
×
404
        }
405

406
        deserializer = factory.getCustomDeserializer(cl);
4✔
407

408
        if (deserializer != null) {
2!
409
            return deserializer;
×
410
        }
411

412
        if (Collection.class.isAssignableFrom(cl)) {
4✔
413
            deserializer = new CollectionDeserializer(cl);
6✔
414
        } else if (Map.class.isAssignableFrom(cl)) {
4✔
415
            deserializer = new MapDeserializer(cl);
6✔
416
        } else if (Iterator.class.isAssignableFrom(cl)) {
4!
417
            deserializer = IteratorDeserializer.create();
×
418
        } else if (Annotation.class.isAssignableFrom(cl)) {
4✔
419
            deserializer = new AnnotationDeserializer(cl);
6✔
420
        } else if (cl.isInterface()) {
3!
421
            deserializer = new ObjectDeserializer(cl);
×
422
        } else if (cl.isArray()) {
3✔
423
            deserializer = new ArrayDeserializer(cl.getComponentType());
7✔
424
        } else if (Enumeration.class.isAssignableFrom(cl)) {
4!
425
            deserializer = EnumerationDeserializer.create();
×
426
        } else if (Enum.class.isAssignableFrom(cl)) {
4✔
427
            deserializer = new EnumDeserializer(cl);
6✔
428
        } else if (Class.class.equals(cl)) {
4✔
429
            deserializer = new ClassDeserializer(getClassLoader());
7✔
430
        } else if (java.util.BitSet.class.equals(cl)) {
4✔
431
            deserializer = new BitSetDeserializer(fieldDeserializer2Factory);
7✔
432
        } else if (Calendar.class.isAssignableFrom(cl)) {
4✔
433
            deserializer = new CalendarDeserializer(cl);
6✔
434
        } else {
435
            deserializer = getDefaultDeserializer(cl);
4✔
436
        }
437

438
        return deserializer;
2✔
439
    }
440

441
    /**
442
     * Returns a custom serializer the class
443
     *
444
     * @param cl the class of the object that needs to be serialized.
445
     *
446
     * @return a serializer object for the serialization.
447
     */
448
    protected Deserializer getCustomDeserializer(Class<?> cl) {
449
        try {
450
            Class<?> serClass = Class.forName(cl.getName() + "HessianDeserializer", false, cl.getClassLoader());
×
451

452
            return (Deserializer) serClass.getDeclaredConstructor().newInstance();
×
453
        } catch (ClassNotFoundException e) {
×
454
            log.log(Level.FINEST, e.toString(), e);
×
455

456
            return null;
×
457
        } catch (Exception e) {
×
458
            log.log(Level.FINE, e.toString(), e);
×
459

460
            return null;
×
461
        }
462
    }
463

464
    /**
465
     * Returns the default serializer for a class that isn't matched
466
     * directly.  Application can override this method to produce
467
     * bean-style serialization instead of field serialization.
468
     *
469
     * @param cl the class of the object that needs to be serialized.
470
     *
471
     * @return a serializer object for the serialization.
472
     */
473
    protected Deserializer getDefaultDeserializer(Class<?> cl) {
474
        if (InputStream.class.equals(cl)) {
4!
475
            return InputStreamDeserializer.DESER;
×
476
        }
477

478
        if (isEnableUnsafeSerializer) {
3✔
479
            return new UnsafeDeserializer(cl, fieldDeserializer2Factory);
7✔
480
        } else {
481
            return new JavaDeserializer(cl, fieldDeserializer2Factory);
7✔
482
        }
483
    }
484

485
    /**
486
     * Reads the object as a list.
487
     */
488
    public Object readList(AbstractHessianDecoder in, int length, String type) throws IOException {
489
        Deserializer deserializer = getDeserializer(type);
4✔
490

491
        if (deserializer != null) {
2✔
492
            return deserializer.readList(in, length);
5✔
493
        } else {
494
            return new CollectionDeserializer(ArrayList.class).readList(in, length);
8✔
495
        }
496
    }
497

498
    /**
499
     * Reads the object as a map.
500
     */
501
    public Object readMap(AbstractHessianDecoder in, String type) throws IOException {
502
        Deserializer deserializer = getDeserializer(type);
4✔
503

504
        if (deserializer != null) {
2✔
505
            return deserializer.readMap(in);
4✔
506
        } else if (hashMapDeserializer != null) {
3!
507
            return hashMapDeserializer.readMap(in);
5✔
508
        } else {
509
            hashMapDeserializer = new MapDeserializer(HashMap.class);
×
510

511
            return hashMapDeserializer.readMap(in);
×
512
        }
513
    }
514

515
    /**
516
     * Reads the object as a map.
517
     */
518
    public Object readObject(AbstractHessianDecoder in, String type, String[] fieldNames) throws IOException {
519
        Deserializer deserializer = getDeserializer(type);
×
520

521
        if (deserializer != null) {
×
522
            return deserializer.readObject(in, fieldNames);
×
523
        } else if (hashMapDeserializer != null) {
×
524
            return hashMapDeserializer.readObject(in, fieldNames);
×
525
        } else {
526
            hashMapDeserializer = new MapDeserializer(HashMap.class);
×
527

528
            return hashMapDeserializer.readObject(in, fieldNames);
×
529
        }
530
    }
531

532
    /**
533
     * Reads the object as a map.
534
     */
535
    public Deserializer getObjectDeserializer(String type, Class<?> cl) throws HessianProtocolException {
536
        Deserializer reader = getObjectDeserializer(type);
4✔
537

538
        if (cl == null
4✔
539
                || cl.equals(reader.getType())
5✔
540
                || cl.isAssignableFrom(reader.getType())
4✔
541
                || reader.isReadResolve()
4✔
542
                || HessianHandle.class.isAssignableFrom(reader.getType())) {
3!
543
            return reader;
2✔
544
        }
545

546
        if (log.isLoggable(Level.FINE)) {
4!
547
            log.fine("hessian: expected deserializer '" + cl.getName() + "' at '" + type + "' ("
×
548
                    + reader.getType().getName() + ")");
×
549
        }
550

551
        return getDeserializer(cl);
4✔
552
    }
553

554
    /**
555
     * Reads the object as a map.
556
     */
557
    public Deserializer getObjectDeserializer(String type) throws HessianProtocolException {
558
        Deserializer deserializer = getDeserializer(type);
4✔
559

560
        if (deserializer != null) {
2✔
561
            return deserializer;
2✔
562
        } else if (hashMapDeserializer != null) {
3✔
563
            return hashMapDeserializer;
3✔
564
        } else {
565
            hashMapDeserializer = new MapDeserializer(HashMap.class);
6✔
566

567
            return hashMapDeserializer;
3✔
568
        }
569
    }
570

571
    /**
572
     * Reads the object as a map.
573
     */
574
    public Deserializer getListDeserializer(String type, Class<?> cl) throws HessianProtocolException {
575
        Deserializer reader = getListDeserializer(type);
4✔
576

577
        if (cl == null || cl.equals(reader.getType()) || cl.isAssignableFrom(reader.getType())) {
12✔
578
            return reader;
2✔
579
        }
580

581
        if (log.isLoggable(Level.FINE)) {
4!
582
            log.fine("hessian: expected '" + cl.getName() + "' at '" + type + "' ("
×
583
                    + reader.getType().getName() + ")");
×
584
        }
585

586
        return getDeserializer(cl);
4✔
587
    }
588

589
    /**
590
     * Reads the object as a map.
591
     */
592
    public Deserializer getListDeserializer(String type) throws HessianProtocolException {
593
        Deserializer deserializer = getDeserializer(type);
4✔
594

595
        if (deserializer != null) {
2✔
596
            return deserializer;
2✔
597
        } else if (arrayListDeserializer != null) {
3✔
598
            return arrayListDeserializer;
3✔
599
        } else {
600
            arrayListDeserializer = new CollectionDeserializer(ArrayList.class);
6✔
601

602
            return arrayListDeserializer;
3✔
603
        }
604
    }
605

606
    /**
607
     * Returns a deserializer based on a string type.
608
     */
609
    public Deserializer getDeserializer(String type) throws HessianProtocolException {
610
        if (type == null || type.isEmpty()) {
5!
611
            return null;
2✔
612
        }
613

614
        Deserializer deserializer = cachedTypeDeserializerMap.get(type);
6✔
615

616
        if (deserializer != null) {
2✔
617
            return deserializer;
2✔
618
        }
619

620
        deserializer = STATIC_TYPE_MAP.get(type);
5✔
621
        if (deserializer != null) {
2✔
622
            return deserializer;
2✔
623
        }
624

625
        if (type.startsWith("[")) {
4✔
626
            Deserializer subDeserializer = getDeserializer(type.substring(1));
6✔
627

628
            if (subDeserializer != null) {
2✔
629
                deserializer = new ArrayDeserializer(subDeserializer.getType());
7✔
630
            } else {
631
                deserializer = new ArrayDeserializer(Object.class);
5✔
632
            }
633
        } else {
1✔
634
            try {
635
                Class<?> cl = loadSerializedClass(type);
4✔
636

637
                deserializer = getDeserializer(cl);
4✔
638
            } catch (Exception e) {
1✔
639
                log.warning("Hessian/Burlap: '" + type + "' is an unknown class in " + getClassLoader() + ":\n" + e);
9✔
640

641
                log.log(Level.FINER, e.toString(), e);
6✔
642
            }
1✔
643
        }
644

645
        if (deserializer != null) {
2✔
646
            cachedTypeDeserializerMap.putIfAbsent(type, deserializer);
6✔
647
        }
648

649
        return deserializer;
2✔
650
    }
651

652
    private static void addBasic(Class<?> cl, String typeName, int type) {
653
        Deserializer deserializer = new BasicDeserializer(type);
5✔
654

655
        STATIC_TYPE_MAP.put(typeName, deserializer);
5✔
656
    }
1✔
657

658
    static {
659
        STATIC_TYPE_MAP = new HashMap<>();
4✔
660

661
        addBasic(void.class, "void", BasicSerializer.NULL);
4✔
662

663
        addBasic(Boolean.class, "boolean", BasicSerializer.BOOLEAN);
4✔
664
        addBasic(Byte.class, "byte", BasicSerializer.BYTE);
4✔
665
        addBasic(Short.class, "short", BasicSerializer.SHORT);
4✔
666
        addBasic(Integer.class, "int", BasicSerializer.INTEGER);
4✔
667
        addBasic(Long.class, "long", BasicSerializer.LONG);
4✔
668
        addBasic(Float.class, "float", BasicSerializer.FLOAT);
4✔
669
        addBasic(Double.class, "double", BasicSerializer.DOUBLE);
4✔
670
        addBasic(Character.class, "char", BasicSerializer.CHARACTER_OBJECT);
4✔
671
        addBasic(String.class, "string", BasicSerializer.STRING);
4✔
672
        addBasic(StringBuilder.class, "string", BasicSerializer.STRING_BUILDER);
4✔
673
        addBasic(Object.class, "object", BasicSerializer.OBJECT);
4✔
674
        addBasic(java.util.Date.class, "date", BasicSerializer.DATE);
4✔
675

676
        addBasic(boolean.class, "boolean", BasicSerializer.BOOLEAN);
4✔
677
        addBasic(byte.class, "byte", BasicSerializer.BYTE);
4✔
678
        addBasic(short.class, "short", BasicSerializer.SHORT);
4✔
679
        addBasic(int.class, "int", BasicSerializer.INTEGER);
4✔
680
        addBasic(long.class, "long", BasicSerializer.LONG);
4✔
681
        addBasic(float.class, "float", BasicSerializer.FLOAT);
4✔
682
        addBasic(double.class, "double", BasicSerializer.DOUBLE);
4✔
683
        addBasic(char.class, "char", BasicSerializer.CHARACTER);
4✔
684

685
        addBasic(boolean[].class, "[boolean", BasicSerializer.BOOLEAN_ARRAY);
4✔
686
        addBasic(byte[].class, "[byte", BasicSerializer.BYTE_ARRAY);
4✔
687
        addBasic(short[].class, "[short", BasicSerializer.SHORT_ARRAY);
4✔
688
        addBasic(int[].class, "[int", BasicSerializer.INTEGER_ARRAY);
4✔
689
        addBasic(long[].class, "[long", BasicSerializer.LONG_ARRAY);
4✔
690
        addBasic(float[].class, "[float", BasicSerializer.FLOAT_ARRAY);
4✔
691
        addBasic(double[].class, "[double", BasicSerializer.DOUBLE_ARRAY);
4✔
692
        addBasic(char[].class, "[char", BasicSerializer.CHARACTER_ARRAY);
4✔
693
        addBasic(String[].class, "[string", BasicSerializer.STRING_ARRAY);
4✔
694
        addBasic(Object[].class, "[object", BasicSerializer.OBJECT_ARRAY);
4✔
695

696
        Deserializer objectDeserializer = new JavaDeserializer(Object.class, new FieldDeserializer2Factory());
8✔
697
        STATIC_TYPE_MAP.put("object", objectDeserializer);
5✔
698
        STATIC_TYPE_MAP.put(HessianRemote.class.getName(), RemoteDeserializer.DESER);
6✔
699

700
        ClassLoader systemClassLoader = null;
2✔
701
        try {
702
            systemClassLoader = ClassLoader.getSystemClassLoader();
2✔
703
        } catch (Exception ignored) {
×
704
        }
1✔
705

706
        SYSTEM_CLASS_LOADER = systemClassLoader;
2✔
707
    }
1✔
708
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc