Skip to content

Commit b7c273f

Browse files
committed
1 parent c9d7e50 commit b7c273f

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com;
2+
3+
4+
public class UnusedVariablesFPCheck {
5+
public class DeobfuscatedUpdateManager {
6+
// private interface DataContainer {
7+
// Iterable<ItemElement> getItems();
8+
// }
9+
//
10+
// private interface ModelObject {
11+
// void performAction();
12+
// }
13+
//
14+
// private interface ItemElement {
15+
// ModelObject getDataModel();
16+
// }
17+
//
18+
// private static class SystemConfig {
19+
// static ConfigMode getMode() {
20+
// return ConfigMode.ENABLED;
21+
// }
22+
// }
23+
//
24+
// private enum ConfigMode {
25+
// ENABLED,
26+
// DISABLED
27+
// }
28+
//
29+
// static class A {
30+
// interface GenericCallback<T> { }
31+
// }
32+
33+
/**
34+
* Deobfuscated names with AI from :
35+
* ```java
36+
* package com;
37+
* <p>
38+
* public class BCid51 {
39+
* void HJid232(EJid229 YHid199, Yid24.RIid217<MBid37> QJid241) {
40+
* for (XFid148 RJid242 : YHid199.WIid222()) {
41+
* int DHid178;
42+
* if (Fid5.BGid151() == CGid152.DGid153) {
43+
* MBid37 IHid183 = RJid242.OFid139();
44+
* IHid183.AGid150();
45+
* }
46+
* }
47+
* }
48+
* }
49+
* ```
50+
*/
51+
void processUpdates(
52+
DataContainer container
53+
// REMARK : the issue arises from the A.GenericCallback<ModelObject> callback that is not even used (indirect type resolution problem)
54+
, A.GenericCallback<X> callback
55+
) {
56+
for (ItemElement element : container.getItems()) {
57+
if (SystemConfig.getMode() == ConfigMode.ENABLED) {
58+
ModelObject dataModel = element.getDataModel();
59+
dataModel.performAction();
60+
}
61+
}
62+
}
63+
64+
}
65+
66+
static class StringConcatenation {
67+
// private class AClass {
68+
// private class BClass<T> {
69+
// public T b;
70+
// }
71+
// }
72+
73+
public String doSomething(AClass.BClass<String> instance) {
74+
String c = "Hi"; // Rule S1854
75+
return instance.b + c;
76+
}
77+
}
78+
79+
static class EnhancedSwitch {
80+
// private enum DocumentStatus {
81+
// DOC01,
82+
// DOC02
83+
// }
84+
//
85+
// private interface Document {
86+
// void setStatus(DocumentStatus status);
87+
// }
88+
//
89+
// private interface Event {
90+
// }
91+
//
92+
// private class SimpleStatusChangedEvent implements Event {
93+
// }
94+
//
95+
// private class NeedClientRecheckEvent implements Event {
96+
// }
97+
// private interface DocumentRepository {
98+
// void save(Document document);
99+
// }
100+
101+
void ko(Event event, Document document, DocumentRepository documentRepository) {
102+
final DocumentStatus status = switch (event) {
103+
case SimpleStatusChangedEvent ignored -> DocumentStatus.DOC01;
104+
case NeedClientRecheckEvent ignored -> DocumentStatus.DOC02;
105+
};
106+
document.setStatus(status);
107+
// ...
108+
documentRepository.save(document);
109+
}
110+
111+
}
112+
113+
class Obvious {
114+
// void obvious() {
115+
// int i = 0; // doesn't raise issue
116+
// i = 1; // raises issue
117+
// }
118+
}
119+
}

java-checks/src/test/java/org/sonar/java/checks/DeadStoreCheckTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ void test_non_compiling() {
5151
.verifyIssues();
5252
}
5353

54+
@Test
55+
void test_fp() {
56+
CheckVerifier.newVerifier()
57+
.onFile(TestUtils.mainCodeSourcesPath("checks/UnusedVariablesFPCheck.java"))
58+
.withJavaVersion(14)
59+
.withCheck(new DeadStoreCheck())
60+
.verifyNoIssues();
61+
}
62+
5463
private static class EraseSymbols extends BaseTreeVisitor {
5564

5665
@Override

java-frontend/src/main/java/org/sonar/java/model/Symbols.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public final boolean isTypeSymbol() {
9999
}
100100

101101
@Override
102-
public final boolean isMethodSymbol() {
102+
public boolean isMethodSymbol() {
103103
return false;
104104
}
105105

@@ -340,6 +340,9 @@ public boolean isVarArgsMethod() {
340340
public boolean isNativeMethod() {
341341
return false;
342342
}
343+
344+
@Override
345+
public boolean isMethodSymbol() { return true; }
343346
}
344347

345348
public static final class UnknownType implements Type {

0 commit comments

Comments
 (0)