1
+ package me .chanjar .weixin .cp .config .impl ;
2
+
3
+ import me .chanjar .weixin .common .redis .WxRedisOps ;
4
+
5
+ /**
6
+ * Demonstration of the fix for toString() StackOverflowError issue
7
+ */
8
+ public class DemoToStringFix {
9
+
10
+ public static void main (String [] args ) {
11
+ System .out .println ("=== Demonstrating toString() Fix for WxCp Redis Config ===" );
12
+
13
+ // Create a simple stub WxRedisOps implementation for testing
14
+ WxRedisOps stubRedisOps = new WxRedisOps () {
15
+ @ Override
16
+ public String getValue (String key ) { return null ; }
17
+ @ Override
18
+ public void setValue (String key , String value , int expire , java .util .concurrent .TimeUnit timeUnit ) {}
19
+ @ Override
20
+ public Long getExpire (String key ) { return null ; }
21
+ @ Override
22
+ public void expire (String key , int expire , java .util .concurrent .TimeUnit timeUnit ) {}
23
+ @ Override
24
+ public java .util .concurrent .locks .Lock getLock (String key ) { return null ; }
25
+ };
26
+
27
+ // Test AbstractWxCpInRedisConfigImpl directly with our stub
28
+ AbstractWxCpInRedisConfigImpl config = new AbstractWxCpInRedisConfigImpl (stubRedisOps , "demo:" ) {
29
+ // Anonymous class to test the abstract parent
30
+ };
31
+
32
+ config .setCorpId ("demoCorpId" );
33
+ config .setAgentId (1001 );
34
+
35
+ System .out .println ("Testing toString() method:" );
36
+ try {
37
+ String result = config .toString ();
38
+ System .out .println ("✓ Success! toString() returned: " + result );
39
+ System .out .println ("✓ No StackOverflowError occurred" );
40
+
41
+ // Verify the result contains expected information and excludes redisOps
42
+ boolean containsCorpId = result .contains ("demoCorpId" );
43
+ boolean containsAgentId = result .contains ("1001" );
44
+ boolean containsKeyPrefix = result .contains ("demo:" );
45
+ boolean excludesRedisOps = !result .contains ("redisOps" ) && !result .contains ("WxRedisOps" );
46
+
47
+ System .out .println ("✓ Contains corpId: " + containsCorpId );
48
+ System .out .println ("✓ Contains agentId: " + containsAgentId );
49
+ System .out .println ("✓ Contains keyPrefix: " + containsKeyPrefix );
50
+ System .out .println ("✓ Excludes redisOps: " + excludesRedisOps );
51
+
52
+ if (containsCorpId && containsAgentId && containsKeyPrefix && excludesRedisOps ) {
53
+ System .out .println ("✓ All validations passed!" );
54
+ } else {
55
+ System .out .println ("✗ Some validations failed" );
56
+ }
57
+
58
+ } catch (StackOverflowError e ) {
59
+ System .out .println ("✗ StackOverflowError still occurred - fix failed" );
60
+ } catch (Exception e ) {
61
+ System .out .println ("✗ Unexpected error: " + e .getMessage ());
62
+ }
63
+
64
+ System .out .println ("\n === Demo completed ===" );
65
+ }
66
+ }
0 commit comments