Skip to content

Commit 3368dca

Browse files
committed
Avoid extra existence check in SimpleMetadataReaderFactory
Issue: SPR-16281 (cherry picked from commit 7ad69bf)
1 parent 8670411 commit 3368dca

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReaderFactory.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.core.type.classreading;
1818

19+
import java.io.FileNotFoundException;
1920
import java.io.IOException;
2021

2122
import org.springframework.core.io.DefaultResourceLoader;
@@ -72,10 +73,13 @@ public final ResourceLoader getResourceLoader() {
7273

7374
@Override
7475
public MetadataReader getMetadataReader(String className) throws IOException {
75-
String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
76-
ClassUtils.convertClassNameToResourcePath(className) + ClassUtils.CLASS_FILE_SUFFIX;
77-
Resource resource = this.resourceLoader.getResource(resourcePath);
78-
if (!resource.exists()) {
76+
try {
77+
String resourcePath = ResourceLoader.CLASSPATH_URL_PREFIX +
78+
ClassUtils.convertClassNameToResourcePath(className) + ClassUtils.CLASS_FILE_SUFFIX;
79+
Resource resource = this.resourceLoader.getResource(resourcePath);
80+
return getMetadataReader(resource);
81+
}
82+
catch (FileNotFoundException ex) {
7983
// Maybe an inner class name using the dot name syntax? Need to use the dollar syntax here...
8084
// ClassUtils.forName has an equivalent check for resolution into Class references later on.
8185
int lastDotIndex = className.lastIndexOf('.');
@@ -86,11 +90,11 @@ public MetadataReader getMetadataReader(String className) throws IOException {
8690
ClassUtils.convertClassNameToResourcePath(innerClassName) + ClassUtils.CLASS_FILE_SUFFIX;
8791
Resource innerClassResource = this.resourceLoader.getResource(innerClassResourcePath);
8892
if (innerClassResource.exists()) {
89-
resource = innerClassResource;
93+
return getMetadataReader(innerClassResource);
9094
}
9195
}
96+
throw ex;
9297
}
93-
return getMetadataReader(resource);
9498
}
9599

96100
@Override

0 commit comments

Comments
 (0)