Skip to content

Commit 5b4e21a

Browse files
authored
Fix MixinChecker accidentally skipping mixin classes where the target does not exist (#121)
Signed-off-by: Hendrix-Shen <[email protected]>
1 parent c964c2d commit 5b4e21a

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

magiclib-core/common/src/main/java/top/hendrixshen/magiclib/impl/dependency/DependencyContainer.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,14 @@ public ValueContainer<DependencyCheckResult> checkAsRequire() {
175175
I18n.tr("magiclib.dependency.result.platform.require.fail",
176176
this.platformType, currentPlatformType)));
177177
case PREDICATE:
178+
if (this.predicate == null) {
179+
return ValueContainer.of(new DependencyCheckResult(true, I18n.tr(
180+
"magiclib.dependency.result.predicate.target_obj_not_exist")));
181+
}
182+
178183
boolean testResult = this.predicate.test(this.obj);
179184
return ValueContainer.of(new DependencyCheckResult(testResult, I18n.tr(
180-
"magiclib.dependency.result.predicate.message",
185+
"magiclib.dependency.result.predicate.test_result",
181186
this.predicate.getClass().getName(), testResult)));
182187
}
183188

@@ -232,9 +237,14 @@ public ValueContainer<DependencyCheckResult> checkAsConflict() {
232237
return ValueContainer.of(new DependencyCheckResult(true,
233238
I18n.tr("magiclib.dependency.result.platform.conflict.success", this.platformType)));
234239
case PREDICATE:
240+
if (this.predicate == null) {
241+
return ValueContainer.of(new DependencyCheckResult(false, I18n.tr(
242+
"magiclib.dependency.result.predicate.target_obj_not_exist")));
243+
}
244+
235245
boolean testResult = this.predicate.test(this.obj);
236246
return ValueContainer.of(new DependencyCheckResult(!testResult,
237-
I18n.tr("magiclib.dependency.result.predicate.message",
247+
I18n.tr("magiclib.dependency.result.predicate.test_result",
238248
this.predicate.getClass().getName(), testResult)));
239249
}
240250

magiclib-core/common/src/main/java/top/hendrixshen/magiclib/impl/mixin/checker/SimpleMixinChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public boolean check(String targetClassName, String mixinClassName) {
4444
ClassNode targetClassNode = MixinUtil.getClassNode(targetClassName);
4545
ClassNode mixinClassNode = MixinUtil.getClassNode(mixinClassName);
4646

47-
if (targetClassNode == null || mixinClassNode == null) {
47+
if (mixinClassNode == null) {
4848
return false;
4949
}
5050

magiclib-core/common/src/main/resources/assets/magiclib-core/lang/en_us.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ magiclib:
5353
fail: Running on unexpected platform, expected %1$s, but found %2$s.
5454
success: "Running on expected platform: %1$s."
5555
predicate:
56-
message: Predicate %s test result = %s
56+
test_result: Predicate %1$s test result = %2$s
57+
target_obj_not_exist: Predicate %1$s test target does not exist, skipped.
5758
misc:
5859
version_type:
5960
beta: Public Beta

magiclib-core/common/src/main/resources/assets/magiclib-core/lang/zh_cn.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ magiclib:
5353
fail: "运行在非预期平台, 预期: %1$s, 实际: %2$s."
5454
success: "运行在预期平台: %1$s."
5555
predicate:
56-
message: 谓词 %s 测试结果 = %s
56+
test_result: 谓词 %1$s 测试结果 = %2$s
57+
target_obj_not_exist: 谓词 %1$s 测试目标不存在, 已跳过.
5758
misc:
5859
version_type:
5960
beta: 公共测试版

0 commit comments

Comments
 (0)