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

wuwen5 / hessian / 17190932491

24 Aug 2025 03:32PM UTC coverage: 68.598% (+0.2%) from 68.416%
17190932491

push

github

wuwen5
Bump actions/checkout from 4 to 5

Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v4...v5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

1793 of 2809 branches covered (63.83%)

Branch coverage included in aggregate %.

4173 of 5888 relevant lines covered (70.87%)

3.08 hits per line

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

50.6
hessian2-codec/src/main/java/io/github/wuwen5/hessian/io/WriteReplaceSerializer.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 java.io.IOException;
52
import java.lang.reflect.InvocationTargetException;
53
import java.lang.reflect.Method;
54
import lombok.extern.slf4j.Slf4j;
55

56
/**
57
 * Serializing an object for known object types.
58
 */
59
@Slf4j
4✔
60
public class WriteReplaceSerializer extends AbstractSerializer {
61
    private Object writeReplaceFactory;
62
    private Method writeReplace;
63
    private final Serializer baseSerializer;
64

65
    public WriteReplaceSerializer(Class<?> cl, ClassLoader loader, Serializer baseSerializer) {
2✔
66
        introspectWriteReplace(cl, loader);
4✔
67

68
        this.baseSerializer = baseSerializer;
3✔
69
    }
1✔
70

71
    private void introspectWriteReplace(Class<?> cl, ClassLoader loader) {
72
        try {
73
            String className = cl.getName() + "HessianSerializer";
4✔
74

75
            Class<?> serializerClass = Class.forName(className, false, loader);
×
76

77
            Object serializerObject = serializerClass.getDeclaredConstructor().newInstance();
×
78

79
            Method writeReplaceMethod = getWriteReplace(serializerClass, cl);
×
80

81
            if (writeReplaceMethod != null) {
×
82
                writeReplaceFactory = serializerObject;
×
83
                this.writeReplace = writeReplaceMethod;
×
84
            }
85
        } catch (ClassNotFoundException ignored) {
1✔
86
        } catch (Exception e) {
×
87
            log.trace(e.toString(), e);
×
88
        }
1✔
89

90
        writeReplace = getWriteReplace(cl);
4✔
91
        if (writeReplace != null) {
3!
92
            writeReplace.setAccessible(true);
4✔
93
        }
94
    }
1✔
95

96
    /**
97
     * Returns the writeReplace method
98
     */
99
    protected static Method getWriteReplace(Class<?> cl, Class<?> param) {
100
        for (; cl != null; cl = cl.getSuperclass()) {
×
101
            for (Method method : cl.getDeclaredMethods()) {
×
102
                if ("writeReplace".equals(method.getName())
×
103
                        && method.getParameterTypes().length == 1
×
104
                        && param.equals(method.getParameterTypes()[0])) {
×
105
                    return method;
×
106
                }
107
            }
108
        }
109

110
        return null;
×
111
    }
112

113
    /**
114
     * Returns the writeReplace method
115
     */
116
    protected static Method getWriteReplace(Class<?> cl) {
117
        for (; cl != null; cl = cl.getSuperclass()) {
6!
118
            Method[] methods = cl.getDeclaredMethods();
3✔
119

120
            for (Method method : methods) {
16✔
121
                if ("writeReplace".equals(method.getName()) && method.getParameterTypes().length == 0) {
9!
122
                    return method;
2✔
123
                }
124
            }
125
        }
126

127
        return null;
×
128
    }
129

130
    @Override
131
    public void writeObject(Object obj, AbstractHessianEncoder out) throws IOException {
132
        int ref = out.getRef(obj);
4✔
133

134
        if (ref >= 0) {
2!
135
            out.writeRef(ref);
×
136

137
            return;
×
138
        }
139

140
        Object repl;
141

142
        repl = writeReplace(obj);
4✔
143

144
        if (obj == repl) {
3✔
145
            if (log.isDebugEnabled()) {
3!
146
                log.debug(
18✔
147
                        "{}: Hessian writeReplace error.  The writeReplace method ({}) must not return the same object: {}",
148
                        this,
149
                        writeReplace,
150
                        obj);
151
            }
152

153
            baseSerializer.writeObject(obj, out);
5✔
154

155
            return;
1✔
156
        }
157

158
        out.writeObject(repl);
3✔
159

160
        out.replaceRef(repl, obj);
5✔
161
    }
1✔
162

163
    @Override
164
    protected Object writeReplace(Object obj) {
165
        try {
166
            if (writeReplaceFactory != null) {
3!
167
                return writeReplace.invoke(writeReplaceFactory, obj);
×
168
            } else {
169
                return writeReplace.invoke(obj);
7✔
170
            }
171
        } catch (InvocationTargetException e) {
×
172
            throw new IllegalStateException(e.getCause());
×
173
        } catch (IllegalAccessException e) {
×
174
            throw new IllegalStateException(e);
×
175
        }
176
    }
177
}
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