Skip to content

Commit 7ad69bf

Browse files
committed
Avoid extra existence check in SimpleMetadataReaderFactory
Issue: SPR-16281
1 parent 1a154c3 commit 7ad69bf

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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;
@@ -73,10 +74,13 @@ public final ResourceLoader getResourceLoader() {
7374

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

97101
@Override

0 commit comments

Comments
 (0)