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

wuwen5 / hessian / 17177490298

23 Aug 2025 03:42PM UTC coverage: 68.416% (+11.8%) from 56.631%
17177490298

push

github

web-flow
refactor: fix sonar S2184 and code clean (#29)

1781 of 2793 branches covered (63.77%)

Branch coverage included in aggregate %.

4152 of 5879 relevant lines covered (70.62%)

3.07 hits per line

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

80.09
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();
×
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 {
431
            deserializer = getDefaultDeserializer(cl);
4✔
432
        }
433

434
        return deserializer;
2✔
435
    }
436

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

448
            return (Deserializer) serClass.getDeclaredConstructor().newInstance();
×
449
        } catch (ClassNotFoundException e) {
×
450
            log.log(Level.FINEST, e.toString(), e);
×
451

452
            return null;
×
453
        } catch (Exception e) {
×
454
            log.log(Level.FINE, e.toString(), e);
×
455

456
            return null;
×
457
        }
458
    }
459

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

474
        if (isEnableUnsafeSerializer) {
3✔
475
            return new UnsafeDeserializer(cl, fieldDeserializer2Factory);
7✔
476
        } else {
477
            return new JavaDeserializer(cl, fieldDeserializer2Factory);
7✔
478
        }
479
    }
480

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

487
        if (deserializer != null) {
2✔
488
            return deserializer.readList(in, length);
5✔
489
        } else {
490
            return new CollectionDeserializer(ArrayList.class).readList(in, length);
8✔
491
        }
492
    }
493

494
    /**
495
     * Reads the object as a map.
496
     */
497
    public Object readMap(AbstractHessianDecoder in, String type) throws IOException {
498
        Deserializer deserializer = getDeserializer(type);
4✔
499

500
        if (deserializer != null) {
2✔
501
            return deserializer.readMap(in);
4✔
502
        } else if (hashMapDeserializer != null) {
3!
503
            return hashMapDeserializer.readMap(in);
5✔
504
        } else {
505
            hashMapDeserializer = new MapDeserializer(HashMap.class);
×
506

507
            return hashMapDeserializer.readMap(in);
×
508
        }
509
    }
510

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

517
        if (deserializer != null) {
×
518
            return deserializer.readObject(in, fieldNames);
×
519
        } else if (hashMapDeserializer != null) {
×
520
            return hashMapDeserializer.readObject(in, fieldNames);
×
521
        } else {
522
            hashMapDeserializer = new MapDeserializer(HashMap.class);
×
523

524
            return hashMapDeserializer.readObject(in, fieldNames);
×
525
        }
526
    }
527

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

534
        if (cl == null
4✔
535
                || cl.equals(reader.getType())
5✔
536
                || cl.isAssignableFrom(reader.getType())
4✔
537
                || reader.isReadResolve()
4✔
538
                || HessianHandle.class.isAssignableFrom(reader.getType())) {
3!
539
            return reader;
2✔
540
        }
541

542
        if (log.isLoggable(Level.FINE)) {
4!
543
            log.fine("hessian: expected deserializer '" + cl.getName() + "' at '" + type + "' ("
×
544
                    + reader.getType().getName() + ")");
×
545
        }
546

547
        return getDeserializer(cl);
4✔
548
    }
549

550
    /**
551
     * Reads the object as a map.
552
     */
553
    public Deserializer getObjectDeserializer(String type) throws HessianProtocolException {
554
        Deserializer deserializer = getDeserializer(type);
4✔
555

556
        if (deserializer != null) {
2✔
557
            return deserializer;
2✔
558
        } else if (hashMapDeserializer != null) {
3✔
559
            return hashMapDeserializer;
3✔
560
        } else {
561
            hashMapDeserializer = new MapDeserializer(HashMap.class);
6✔
562

563
            return hashMapDeserializer;
3✔
564
        }
565
    }
566

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

573
        if (cl == null || cl.equals(reader.getType()) || cl.isAssignableFrom(reader.getType())) {
12✔
574
            return reader;
2✔
575
        }
576

577
        if (log.isLoggable(Level.FINE)) {
4!
578
            log.fine("hessian: expected '" + cl.getName() + "' at '" + type + "' ("
×
579
                    + reader.getType().getName() + ")");
×
580
        }
581

582
        return getDeserializer(cl);
4✔
583
    }
584

585
    /**
586
     * Reads the object as a map.
587
     */
588
    public Deserializer getListDeserializer(String type) throws HessianProtocolException {
589
        Deserializer deserializer = getDeserializer(type);
4✔
590

591
        if (deserializer != null) {
2✔
592
            return deserializer;
2✔
593
        } else if (arrayListDeserializer != null) {
3✔
594
            return arrayListDeserializer;
3✔
595
        } else {
596
            arrayListDeserializer = new CollectionDeserializer(ArrayList.class);
6✔
597

598
            return arrayListDeserializer;
3✔
599
        }
600
    }
601

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

610
        Deserializer deserializer = cachedTypeDeserializerMap.get(type);
6✔
611

612
        if (deserializer != null) {
2✔
613
            return deserializer;
2✔
614
        }
615

616
        deserializer = STATIC_TYPE_MAP.get(type);
5✔
617
        if (deserializer != null) {
2✔
618
            return deserializer;
2✔
619
        }
620

621
        if (type.startsWith("[")) {
4✔
622
            Deserializer subDeserializer = getDeserializer(type.substring(1));
6✔
623

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

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

637
                log.log(Level.FINER, e.toString(), e);
6✔
638
            }
1✔
639
        }
640

641
        if (deserializer != null) {
2✔
642
            cachedTypeDeserializerMap.putIfAbsent(type, deserializer);
6✔
643
        }
644

645
        return deserializer;
2✔
646
    }
647

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

651
        STATIC_TYPE_MAP.put(typeName, deserializer);
5✔
652
    }
1✔
653

654
    static {
655
        STATIC_TYPE_MAP = new HashMap<>();
4✔
656

657
        addBasic(void.class, "void", BasicSerializer.NULL);
4✔
658

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

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

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

692
        Deserializer objectDeserializer = new JavaDeserializer(Object.class, new FieldDeserializer2Factory());
8✔
693
        STATIC_TYPE_MAP.put("object", objectDeserializer);
5✔
694
        STATIC_TYPE_MAP.put(HessianRemote.class.getName(), RemoteDeserializer.DESER);
6✔
695

696
        ClassLoader systemClassLoader = null;
2✔
697
        try {
698
            systemClassLoader = ClassLoader.getSystemClassLoader();
2✔
699
        } catch (Exception ignored) {
×
700
        }
1✔
701

702
        SYSTEM_CLASS_LOADER = systemClassLoader;
2✔
703
    }
1✔
704
}
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