Skip to content

Commit 2677766

Browse files
Mikhail Pyltsinintellij-monorepo-bot
Mikhail Pyltsin
authored andcommitted
IJ-CR-153375 [java-decompiler] IDEA-289211 set limits for some cases in decompiler
- change messages - add test cases GitOrigin-RevId: 8347f136818567abccf56a4c110b77456870fd4e
1 parent 705127a commit 2677766

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/org/jetbrains/java/decompiler/main/collectors/LimitContainer.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,41 @@
88
import java.util.Map;
99
import java.util.concurrent.atomic.AtomicLong;
1010

11-
import static org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences.*;
11+
import static org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences.MAX_DIRECT_NODES_COUNT;
12+
import static org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences.MAX_DIRECT_VARIABLE_NODE_COUNT;
1213

1314
public class LimitContainer {
1415

1516
private final int maxDirectNodeCount;//-1 - don't check
1617
@NotNull
1718
private final AtomicLong directNodeCount = new AtomicLong();
18-
@NotNull
19-
private final String maxDirectNodeCountMessage;
2019

2120
private final int ssaConstructorSparseExRecordCount;//-1 - don't check
22-
@NotNull
23-
private final String ssaConstructorSparseExRecordCountMessage;
2421

2522
public LimitContainer(@NotNull Map<String, Object> properties) {
2623
maxDirectNodeCount = (int)properties.getOrDefault(MAX_DIRECT_NODES_COUNT, -1);
27-
maxDirectNodeCountMessage = (String)properties.getOrDefault(MAX_DIRECT_NODES_COUNT_MESSAGE, "Limits are exceeded");
2824
ssaConstructorSparseExRecordCount = (int)properties.getOrDefault(MAX_DIRECT_VARIABLE_NODE_COUNT, -1);
29-
ssaConstructorSparseExRecordCountMessage = (String)properties.getOrDefault(MAX_DIRECT_VARIABLE_NODES_COUNT_MESSAGE, "Limits are exceeded");
3025
}
3126

3227
public void incrementAndCheckDirectNodeCount(@NotNull ControlFlowGraph graph) {
3328
long newValue = directNodeCount.addAndGet(graph.getBlocks().size());
3429
if (maxDirectNodeCount != -1 && newValue >= maxDirectNodeCount) {
35-
throw new LimitExceededDecompilerException(maxDirectNodeCountMessage);
30+
throw new LimitExceededDecompilerException(maxDirectNodeCount, newValue, "direct nodes");
3631
}
3732
}
3833

3934
public void checkSFormsFastMapDirect(@NotNull Map<String, SFormsFastMapDirect> inVarVersions,
4035
@NotNull Map<String, SFormsFastMapDirect> outVarVersions) {
36+
int newValue = inVarVersions.size() + outVarVersions.size();
4137
if (ssaConstructorSparseExRecordCount != -1 &&
42-
inVarVersions.size() + outVarVersions.size() > ssaConstructorSparseExRecordCount) {
43-
throw new LimitExceededDecompilerException(ssaConstructorSparseExRecordCountMessage);
38+
newValue > ssaConstructorSparseExRecordCount) {
39+
throw new LimitExceededDecompilerException(ssaConstructorSparseExRecordCount, newValue, "variable nodes");
4440
}
4541
}
4642

4743
public static class LimitExceededDecompilerException extends RuntimeException {
48-
public LimitExceededDecompilerException(String message) {
49-
super(message);
44+
public LimitExceededDecompilerException(long limit, long actualValue, String type) {
45+
super("Limits for %s are exceeded. Current value: %s, limit: %s".formatted(type, actualValue, limit));
5046
}
5147
}
5248
}

src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java

-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public interface IFernflowerPreferences {
6464
String SKIP_EXTRA_FILES = "sef";
6565

6666
String MAX_DIRECT_NODES_COUNT = "mdnc";
67-
String MAX_DIRECT_NODES_COUNT_MESSAGE = "mdncm";
6867
String MAX_DIRECT_VARIABLE_NODE_COUNT = "mdvnc";
69-
String MAX_DIRECT_VARIABLE_NODES_COUNT_MESSAGE = "mdvncm";
7068

7169
Map<String, String> DEFAULTS = getDefaults();
7270

0 commit comments

Comments
 (0)