Improve error reporting when driver class version is unsupported
ClassUtils.isPresent(String, ClassLoader) swallows all Throwables when trying to load a class by name. For this reason UnsupportedClassVersionError will also be swallowed when user code is trying to use a driver library which has been compiled with a later JDK than the one the application is running with. All the user would see was "Cannot load driver class". This change simply propagates the UnsupportedClassVersionNumberError so that it is easier for users to find the root cause of the problem. Closes gh-4082 Closes gh-4091
This commit is contained in:
		
							parent
							
								
									e17eab6430
								
							
						
					
					
						commit
						6978694cb8
					
				| 
						 | 
				
			
			@ -161,7 +161,7 @@ public class DataSourceProperties implements BeanClassLoaderAware, EnvironmentAw
 | 
			
		|||
 | 
			
		||||
	public String getDriverClassName() {
 | 
			
		||||
		if (StringUtils.hasText(this.driverClassName)) {
 | 
			
		||||
			Assert.state(ClassUtils.isPresent(this.driverClassName, null),
 | 
			
		||||
			Assert.state(driverClassIsLoadable(),
 | 
			
		||||
					"Cannot load driver class: " + this.driverClassName);
 | 
			
		||||
			return this.driverClassName;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -182,6 +182,20 @@ public class DataSourceProperties implements BeanClassLoaderAware, EnvironmentAw
 | 
			
		|||
		return driverClassName;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private boolean driverClassIsLoadable() {
 | 
			
		||||
		try {
 | 
			
		||||
			ClassUtils.forName(this.driverClassName, null);
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		catch (UnsupportedClassVersionError ucve) {
 | 
			
		||||
			// driver library has been compiled with a later JDK, propagate error
 | 
			
		||||
			throw ucve;
 | 
			
		||||
		}
 | 
			
		||||
		catch (Throwable t) {
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setDriverClassName(String driverClassName) {
 | 
			
		||||
		this.driverClassName = driverClassName;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue