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

alibaba / jetcache / #448

23 May 2026 01:38PM UTC coverage: 89.341% (+0.4%) from 88.921%
#448

push

areyouok
fix: init fail if Kryo not in classpath

0 of 4 new or added lines in 1 file covered. (0.0%)

27 existing lines in 9 files now uncovered.

5029 of 5629 relevant lines covered (89.34%)

0.89 hits per line

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

63.89
/jetcache-core/src/main/java/com/alicp/jetcache/support/DecoderMap.java
1
/**
2
 * Created on 2018/3/20.
3
 */
4
package com.alicp.jetcache.support;
5

6
import java.util.concurrent.ConcurrentHashMap;
7
import java.util.concurrent.locks.ReentrantLock;
8

9
/**
10
 * @author huangli
11
 */
12
public class DecoderMap {
13

14
    public static final int IDENTITY_NUMBER_JAVA = 0x4A953A80;
15

16
    // int IDENTITY_NUMBER_FASTJSON = 0x4A953A81; not used since 2.5+
17
    // removed in 2.8.0
18
    // int IDENTITY_NUMBER_KRYO4 = 0x4A953A82;
19

20
    /**
21
     * @since 2.7
22
     */
23
    public static final int IDENTITY_NUMBER_KRYO5 = 0xF6E0A5C0;
24

25
    /**
26
     * fastjson2 encoder/decoder is implemented but not register by default.
27
     * This is because json is not good serializable util for java and has many compatible problems.
28
     *
29
     * @see com.alicp.jetcache.anno.support.DefaultEncoderParser
30
     * @see DecoderMap
31
     * @since 2.7
32
     */
33
    public static final int IDENTITY_NUMBER_FASTJSON2 = 0xF6E0A5C1;
34

35
    /**
36
     * jackson3 encoder/decoder is implemented but not register by default.
37
     * This is because json is not good serializable util for java and has many compatible problems.
38
     *
39
     * @see com.alicp.jetcache.anno.support.DefaultEncoderParser
40
     * @see DecoderMap
41
     * @since 2.8
42
     */
43
    public static final int IDENTITY_NUMBER_JACKSON3 = 0xF6E0A5C2;
44

45
    private final ConcurrentHashMap<Integer, AbstractValueDecoder> decoderMap = new ConcurrentHashMap<>();
1✔
46
    private volatile boolean inited = false;
1✔
47
    private final ReentrantLock reentrantLock = new ReentrantLock();
1✔
48

49
    private static final DecoderMap instance = new DecoderMap();
1✔
50

51
    public DecoderMap() {
1✔
52
    }
1✔
53

54
    public static DecoderMap defaultInstance() {
55
        return instance;
1✔
56
    }
57

58
    public AbstractValueDecoder getDecoder(int identityNumber) {
59
        return decoderMap.get(identityNumber);
1✔
60
    }
61

62
    public void register(int identityNumber, AbstractValueDecoder decoder) {
63
        decoderMap.put(identityNumber, decoder);
1✔
64
    }
1✔
65

66
    public void clear() {
UNCOV
67
        decoderMap.clear();
×
UNCOV
68
    }
×
69

70
    public ReentrantLock getLock() {
UNCOV
71
        return reentrantLock;
×
72
    }
73

74
    public void setInited(boolean inited) {
UNCOV
75
        this.inited = inited;
×
UNCOV
76
    }
×
77

78
    public void initDefaultDecoder() {
79
        if (inited) {
1✔
80
            return;
1✔
81
        }
82
        reentrantLock.lock();
1✔
83
        try {
84
            if (inited) {
1✔
UNCOV
85
                return;
×
86
            }
87
            register(IDENTITY_NUMBER_JAVA, defaultJavaValueDecoder());
1✔
88
            try {
89
                Class.forName("com.esotericsoftware.kryo.kryo5.Kryo");
1✔
90
                register(IDENTITY_NUMBER_KRYO5, Kryo5ValueDecoder.INSTANCE);
1✔
UNCOV
91
            } catch (ClassNotFoundException e) {
×
92
                // the com.esotericsoftware:kryo should be 5+
93
                try {
NEW
94
                    Class.forName("com.esotericsoftware.kryo.Kryo");
×
NEW
95
                    register(IDENTITY_NUMBER_KRYO5, KryoValueDecoder.INSTANCE);
×
NEW
96
                } catch (ClassNotFoundException e2) {
×
97
                    // kryo is not on the classpath, skip registration
NEW
98
                }
×
99
            }
1✔
100
            // register(IDENTITY_NUMBER_FASTJSON2, Fastjson2ValueDecoder.INSTANCE);
101
            // register(IDENTITY_NUMBER_JACKSON3, Jackson3ValueDecoder.INSTANCE);
102
            inited = true;
1✔
103
        } finally {
104
            reentrantLock.unlock();
1✔
105
        }
106
    }
1✔
107

108
    public static JavaValueDecoder defaultJavaValueDecoder() {
109
        try {
110
            Class.forName("org.springframework.core.ConfigurableObjectInputStream");
1✔
111
            return SpringJavaValueDecoder.INSTANCE;
1✔
UNCOV
112
        } catch (ClassNotFoundException e) {
×
UNCOV
113
            return JavaValueDecoder.INSTANCE;
×
114
        }
115
    }
116

117

118
}
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