<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=fenrir" rel="nofollow">Donny A. Wijaya</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7229?redirect=false" rel="nofollow">SPR-7229</a></strong> and commented</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.2</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398087748" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9424" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9424/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9424">#9424</a> Add additional redirect prefixes to allow for more control over redirect behavior (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=marvel_ss" rel="nofollow">Marvel</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5212?redirect=false" rel="nofollow">SPR-5212</a></strong> and commented</p>
<p dir="auto">This is the worst possible kind of bug report, and so I apologize in advance, but it has only appeared once in production and was not reproducible.   On top of that, the actual case that generates the error seems to be pretty much impossible.  The cast exception you see below, is in this Spring code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/**
 * Return the class name of the wrapped bean.
 */
public String getBeanClassName() {
	if (this.beanClass instanceof Class) {
		return ((Class) this.beanClass).getName();
	}
	else {
		return (String) this.beanClass;
	}
}"><pre class="notranslate"><code class="notranslate">/**
 * Return the class name of the wrapped bean.
 */
public String getBeanClassName() {
	if (this.beanClass instanceof Class) {
		return ((Class) this.beanClass).getName();
	}
	else {
		return (String) this.beanClass;
	}
}
</code></pre></div>
<p dir="auto">As you can see the method checks if the field is a Class, and casts to it if it is.  However, in this case below, for some reason, it tried to cast it to a String even though it was a Class.   I don't know if this is some strange classloading issue, a JVM bug, or what, but I figured you would want to at least see it.</p>
<p dir="auto">Stack trace:</p>
<hr>
<p dir="auto">org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityModel' defined in class path resource [applicationContext-siteresources.xml]: Initialization of bean failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String<br>
at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClassName(AbstractBeanDefinition.java:311)<br>
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:327)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1066)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:349)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:881)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:829)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:424)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:229)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)<br>
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:733)<br>
at com.cargurus.site.interceptor.ModelInterceptor.intercept(ModelInterceptor.java:75)</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.5</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398091345" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9886" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9886/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9886">#9886</a> Class cast exception in AbstractBeanDefinition.getBeanClassName(AbstractBeanDefinition.java:305) (<em><strong>"duplicates"</strong></em>)</li>
</ul>