Introduce ClassFormatException and spring.classformat.ignore property
Closes gh-27691
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2002-2023 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.type.classreading;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Exception that indicates an incompatible class format encountered
|
||||
* in a class file during metadata reading.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 6.1.2
|
||||
* @see MetadataReaderFactory#getMetadataReader(Resource)
|
||||
* @see ClassFormatError
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ClassFormatException extends IOException {
|
||||
|
||||
/**
|
||||
* Construct a new {@code ClassFormatException} with the
|
||||
* supplied message.
|
||||
* @param message the detail message
|
||||
*/
|
||||
public ClassFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@code ClassFormatException} with the
|
||||
* supplied message and cause.
|
||||
* @param message the detail message
|
||||
* @param cause the root cause
|
||||
*/
|
||||
public ClassFormatException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -35,6 +35,7 @@ public interface MetadataReaderFactory {
|
||||
* Obtain a MetadataReader for the given class name.
|
||||
* @param className the class name (to be resolved to a ".class" file)
|
||||
* @return a holder for the ClassReader instance (never {@code null})
|
||||
* @throws ClassFormatException in case of an incompatible class format
|
||||
* @throws IOException in case of I/O failure
|
||||
*/
|
||||
MetadataReader getMetadataReader(String className) throws IOException;
|
||||
@@ -43,6 +44,7 @@ public interface MetadataReaderFactory {
|
||||
* Obtain a MetadataReader for the given resource.
|
||||
* @param resource the resource (pointing to a ".class" file)
|
||||
* @return a holder for the ClassReader instance (never {@code null})
|
||||
* @throws ClassFormatException in case of an incompatible class format
|
||||
* @throws IOException in case of I/O failure
|
||||
*/
|
||||
MetadataReader getMetadataReader(Resource resource) throws IOException;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -35,8 +35,8 @@ import org.springframework.lang.Nullable;
|
||||
*/
|
||||
final class SimpleMetadataReader implements MetadataReader {
|
||||
|
||||
private static final int PARSING_OPTIONS = ClassReader.SKIP_DEBUG
|
||||
| ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES;
|
||||
private static final int PARSING_OPTIONS =
|
||||
(ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
|
||||
|
||||
private final Resource resource;
|
||||
|
||||
@@ -56,8 +56,10 @@ final class SimpleMetadataReader implements MetadataReader {
|
||||
return new ClassReader(is);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
throw new IOException("ASM ClassReader failed to parse class file - " +
|
||||
"probably due to a new Java class file version that isn't supported yet: " + resource, ex);
|
||||
throw new ClassFormatException("ASM ClassReader failed to parse class file - " +
|
||||
"probably due to a new Java class file version that is not supported yet. " +
|
||||
"Consider compiling with a lower '-target' or upgrade your framework version. " +
|
||||
"Affected class: " + resource, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user