…しかしStackOverflowで動かなかった!!(ドラクエ風に)
... at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:693) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:693) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:693) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:693) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:693) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:693) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:693) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:693) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.util.ObjectUtils.nullSafeHashCode(ObjectUtils.java:336) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] at org.springframework.core.ResolvableType.hashCode(ResolvableType.java:693) ~[spring-core-4.0.0.RELEASE.jar:4.0.0.RELEASE] ...
なんやねん
該当の箇所を見てみたらこの通り。
ResolvableType.java
@Override public int hashCode() { int hashCode = ObjectUtils.nullSafeHashCode(this.type); hashCode = hashCode * 31 + ObjectUtils.nullSafeHashCode( // ←693行目はココ this.variableResolver == null ? null : this.variableResolver.getSource()); hashCode = hashCode * 31 + ObjectUtils.nullSafeHashCode(this.componentType); return hashCode; }
ObjectUtils.java
public static int nullSafeHashCode(Object obj) { if (obj == null) { return 0; } if (obj.getClass().isArray()) { if (obj instanceof Object[]) { return nullSafeHashCode((Object[]) obj); } if (obj instanceof boolean[]) { return nullSafeHashCode((boolean[]) obj); } if (obj instanceof byte[]) { return nullSafeHashCode((byte[]) obj); } if (obj instanceof char[]) { return nullSafeHashCode((char[]) obj); } if (obj instanceof double[]) { return nullSafeHashCode((double[]) obj); } if (obj instanceof float[]) { return nullSafeHashCode((float[]) obj); } if (obj instanceof int[]) { return nullSafeHashCode((int[]) obj); } if (obj instanceof long[]) { return nullSafeHashCode((long[]) obj); } if (obj instanceof short[]) { return nullSafeHashCode((short[]) obj); } } return obj.hashCode(); // ←336行目はココ }
パッと見た感じ、ResolvableType#hashCodeの
hashCode = hashCode * 31 + ObjectUtils.nullSafeHashCode( this.variableResolver == null ? null : this.variableResolver.getSource());
において、三項演算子のfalse側の式が評価されていて、かつ
this.variableResolver.getSource() == this
という循環参照になっているのではないかと。