Skip to content

Commit

Permalink
Fix when duplication spi class found using SpiLoader (alibaba#3387)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdfive authored Apr 28, 2024
1 parent cd02b1d commit dbd3c06
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ public void load() {
try {
urls = classLoader.getResources(fullFileName);
} catch (IOException e) {
fail("Error locating SPI configuration file, filename=" + fullFileName + ", classloader=" + classLoader, e);
fail("Error locating SPI configuration file,filename=" + fullFileName + ",classloader=" + classLoader, e);
}

if (urls == null || !urls.hasMoreElements()) {
RecordLog.warn("No SPI configuration file, filename=" + fullFileName + ", classloader=" + classLoader);
RecordLog.warn("No SPI configuration file,filename=" + fullFileName + ",classloader=" + classLoader);
return;
}

Expand Down Expand Up @@ -371,8 +371,13 @@ public void load() {
fail("class " + line + " not found", e);
}

if (classMap.containsValue(clazz)) {
RecordLog.warn("duplicate class found,className=" + clazz.getName() + ",SPI configuration file[" + url + "]");
continue;
}

if (!service.isAssignableFrom(clazz)) {
fail("class " + clazz.getName() + "is not subtype of " + service.getName() + ",SPI configuration file=" + fullFileName);
fail("class " + clazz.getName() + "is not subtype of " + service.getName() + ",SPI configuration file[" + url + "]");
}

classList.add(clazz);
Expand All @@ -381,13 +386,13 @@ public void load() {
if (classMap.containsKey(aliasName)) {
Class<? extends S> existClass = classMap.get(aliasName);
fail("Found repeat alias name for " + clazz.getName() + " and "
+ existClass.getName() + ",SPI configuration file=" + fullFileName);
+ existClass.getName() + ",SPI configuration file[" + url + "]");
}
classMap.put(aliasName, clazz);

if (spi != null && spi.isDefault()) {
if (defaultClass != null) {
fail("Found more than one default Provider, SPI configuration file=" + fullFileName);
fail("Found more than one default Provider,className=" + clazz.getName() + ",SPI configuration file[" + url + "]");
}
defaultClass = clazz;
}
Expand All @@ -400,7 +405,7 @@ public void load() {
, spi == null ? 0 : spi.order());
}
} catch (IOException e) {
fail("error reading SPI configuration file", e);
fail("error reading SPI configuration file[" + url + "]", e);
} finally {
closeResources(in, br);
}
Expand Down

0 comments on commit dbd3c06

Please sign in to comment.