Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix when duplication spi class found using SpiLoader #3387

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@
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);

Check warning on line 332 in sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java

View check run for this annotation

Codecov / codecov/patch

sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java#L332

Added line #L332 was not covered by tests
}

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 @@
fail("class " + line + " not found", e);
}

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

Check warning on line 376 in sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java

View check run for this annotation

Codecov / codecov/patch

sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java#L375-L376

Added lines #L375 - L376 were not covered by tests
}

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 + "]");

Check warning on line 380 in sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java

View check run for this annotation

Codecov / codecov/patch

sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java#L380

Added line #L380 was not covered by tests
}

classList.add(clazz);
Expand All @@ -381,13 +386,13 @@
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 + "]");

Check warning on line 389 in sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java

View check run for this annotation

Codecov / codecov/patch

sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java#L389

Added line #L389 was not covered by tests
}
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 + "]");

Check warning on line 395 in sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java

View check run for this annotation

Codecov / codecov/patch

sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java#L395

Added line #L395 was not covered by tests
}
defaultClass = clazz;
}
Expand All @@ -400,7 +405,7 @@
, spi == null ? 0 : spi.order());
}
} catch (IOException e) {
fail("error reading SPI configuration file", e);
fail("error reading SPI configuration file[" + url + "]", e);

Check warning on line 408 in sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java

View check run for this annotation

Codecov / codecov/patch

sentinel-core/src/main/java/com/alibaba/csp/sentinel/spi/SpiLoader.java#L408

Added line #L408 was not covered by tests
} finally {
closeResources(in, br);
}
Expand Down
Loading