Catch ASM ClassReader's IllegalArgumentException and turn it into a more expressive exception, hinting at the class file version

Issue: SPR-10292
This commit is contained in:
Juergen Hoeller 2013-02-15 18:31:22 +01:00
parent add6a7faa0
commit 5e64723e02
1 changed files with 8 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import org.springframework.asm.ClassReader;
import org.springframework.core.NestedIOException;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
@ -47,10 +48,14 @@ final class SimpleMetadataReader implements MetadataReader {
SimpleMetadataReader(Resource resource, ClassLoader classLoader) throws IOException {
InputStream is = new BufferedInputStream(resource.getInputStream());
ClassReader classReader = null;
ClassReader classReader;
try {
classReader = new ClassReader(is);
}
catch (IllegalArgumentException ex) {
throw new NestedIOException("ASM ClassReader failed to parse class file - " +
"probably due to a new Java class file version that isn't supported yet: " + resource, ex);
}
finally {
is.close();
}
@ -64,6 +69,7 @@ final class SimpleMetadataReader implements MetadataReader {
this.resource = resource;
}
public Resource getResource() {
return this.resource;
}