<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: master</li>
<li>Operating System version: any</li>
<li>Java version: any</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>no step</li>
</ol>
<p dir="auto">Pls. provide [GitHub address] to reproduce this issue.</p>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">1.dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java<br>
2.dubbo-common/src/main/java/org/apache/dubbo/common/config/configcenter/file/FileSystemDynamicConfiguration.java<br>
3.dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java<br>
4.dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java<br>
5.dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ApplicationModel.java<br>
6.dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java<br>
7.dubbo-container/dubbo-container-api/src/main/java/org/apache/dubbo/container/Main.java<br>
8.dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java<br>
9.dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/store/BaseWritableMetadataService.java<br>
10.dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilder.java<br>
11.dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/AbstractMonitorFactory.java<br>
12.dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/DubboLogo.java<br>
13.dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/Server.java<br>
14.dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/QosProcessHandler.java<br>
15.dubbo-plugin/dubbo-qos/src/main/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandler.java<br>
16.dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/TelnetProcessHandlerTest.java<br>
17.dubbo-remoting/dubbo-remoting-http/src/main/java/org/apache/dubbo/remoting/http/servlet/DispatcherServlet.java<br>
18.dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyClient.java<br>
19.dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/DeprecatedFilter.java<br>
20.dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/CallbackServiceCodec.java<br>
21.dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/filter/TraceFilter.java<br>
22.dubbo-rpc/dubbo-rpc-native-thrift/src/main/java/org/apache/dubbo/rpc/protocol/nativethrift/ThriftProtocol.java<br>
23.dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstFactory.java</p>
<p dir="auto">What do you expected from the above steps？</p>
<p dir="auto">1.changes constants in a class to uppercase and underscores between words</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">What actually happens?</p>
<p dir="auto">If there is an exception, please attach the exception trace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/incubator-dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/incubator-dubbo/wiki/FAQ">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.5.10</li>
<li>Operating System version: Mac</li>
<li>Java version: 1.7</li>
</ul>
<h3 dir="auto">Issue Description</h3>
<p dir="auto">In java serialization, the writeReplace method allows the developer to provide a replacement object that will be serialized instead of the original one.</p>
<p dir="auto">Normally, this method would return another object. However, some classes may return itself, e.g. <a href="https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java#L173">JsonMappingException#Reference</a>.</p>
<p dir="auto">In this case, hessian2 would enter an infinite recursion and finally get the <code class="notranslate">java.lang.StackOverflowError</code>.</p>
<h3 dir="auto">Step to reproduce this issue</h3>
<ol dir="auto">
<li>Define a class with a <code class="notranslate">writeReplace</code> method return <code class="notranslate">this</code></li>
</ol>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  public class WriteReplaceReturningItself implements Serializable {

    private static final long serialVersionUID = 1L;

    private String name;

    WriteReplaceReturningItself(String name) {
      this.name = name;
    }

    public String getName() {
      return name;
    }

    /**
     * Some object may return itself for wrapReplace, e.g.
     * https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java#L173
     */
    Object writeReplace() {
      //do some extra things

      return this;
    }
  }"><pre class="notranslate">  <span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">WriteReplaceReturningItself</span> <span class="pl-k">implements</span> <span class="pl-smi">Serializable</span> {

    <span class="pl-k">private</span> <span class="pl-k">static</span> <span class="pl-k">final</span> <span class="pl-smi">long</span> <span class="pl-s1">serialVersionUID</span> = <span class="pl-c1">1L</span>;

    <span class="pl-k">private</span> <span class="pl-smi">String</span> <span class="pl-s1">name</span>;

    <span class="pl-smi">WriteReplaceReturningItself</span>(<span class="pl-smi">String</span> <span class="pl-s1">name</span>) {
      <span class="pl-smi">this</span>.<span class="pl-s1">name</span> = <span class="pl-s1">name</span>;
    }

    <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-en">getName</span>() {
      <span class="pl-k">return</span> <span class="pl-s1">name</span>;
    }

    <span class="pl-c">/**</span>
<span class="pl-c">     * Some object may return itself for wrapReplace, e.g.</span>
<span class="pl-c">     * https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java#L173</span>
<span class="pl-c">     */</span>
    <span class="pl-smi">Object</span> <span class="pl-en">writeReplace</span>() {
      <span class="pl-c">//do some extra things</span>

      <span class="pl-k">return</span> <span class="pl-smi">this</span>;
    }
  }</pre></div>
<ol start="2" dir="auto">
<li>Use <code class="notranslate">Hessian2Output</code> to serialize it</li>
</ol>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  ByteArrayOutputStream bout = new ByteArrayOutputStream();
  Hessian2Output out = new Hessian2Output(bout);

  out.writeObject(data);
  out.flush();"><pre class="notranslate">  <span class="pl-smi">ByteArrayOutputStream</span> <span class="pl-s1">bout</span> = <span class="pl-k">new</span> <span class="pl-smi">ByteArrayOutputStream</span>();
  <span class="pl-smi">Hessian2Output</span> <span class="pl-s1">out</span> = <span class="pl-k">new</span> <span class="pl-smi">Hessian2Output</span>(<span class="pl-s1">bout</span>);

  <span class="pl-s1">out</span>.<span class="pl-en">writeObject</span>(<span class="pl-s1">data</span>);
  <span class="pl-s1">out</span>.<span class="pl-en">flush</span>();</pre></div>
<ol start="3" dir="auto">
<li>Error occurs</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="java.lang.StackOverflowError
  at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:302)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:381)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:383)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)"><pre class="notranslate"><code class="notranslate">java.lang.StackOverflowError
  at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:302)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:381)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:383)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
</code></pre></div>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">The serialization process should complete with no exception or error.</p>
<h3 dir="auto">Actual Result</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="java.lang.StackOverflowError
  at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:302)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:381)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:383)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)"><pre class="notranslate"><code class="notranslate">java.lang.StackOverflowError
  at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:302)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:381)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:383)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
</code></pre></div>