Skip to content

Commit cfd560e

Browse files
author
githubnull
committed
fix: resolve unchecked cast type safety warnings in Burp Suite dialogs
1 parent 988cf23 commit cfd560e

File tree

4 files changed

+51
-28
lines changed

4 files changed

+51
-28
lines changed

src/burpEx/legacy-api/src/main/java/com/sqlmapwebui/burp/dialogs/HeaderRuleDialog.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public boolean isCellEditable(int row, int column) {
164164

165165
// 获取规则配置
166166
JTextField namePrefixField = (JTextField) findComponentByName(ruleConfigPanel, "namePrefix");
167+
@SuppressWarnings("unchecked")
167168
JComboBox<String> strategyCombo = (JComboBox<String>) findComponentByName(ruleConfigPanel, "strategy");
168169
JSpinner prioritySpinner = (JSpinner) findComponentByName(ruleConfigPanel, "priority");
169170
JCheckBox isActiveCheck = (JCheckBox) findComponentByName(ruleConfigPanel, "isActive");
@@ -177,6 +178,7 @@ public boolean isCellEditable(int row, int column) {
177178

178179
String scopeJson = "null";
179180
if (enableScopeCheck != null && enableScopeCheck.isSelected()) {
181+
@SuppressWarnings("unchecked")
180182
JComboBox<String> protocolCombo = (JComboBox<String>) findComponentByName(ruleConfigPanel, "protocol");
181183
JTextField hostField = (JTextField) findComponentByName(ruleConfigPanel, "host");
182184
JTextField pathField = (JTextField) findComponentByName(ruleConfigPanel, "path");

src/burpEx/legacy-api/src/main/java/com/sqlmapwebui/burp/dialogs/SessionHeaderDialog.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ public boolean isCellEditable(int row, int column) {
176176
JCheckBox enableScopeCheck = (JCheckBox) findComponentByName(scopePanel, "enableScope");
177177
String scopeJson = "null";
178178
if (enableScopeCheck != null && enableScopeCheck.isSelected()) {
179-
JComboBox<String> protocolCombo = (JComboBox<String>) findComponentByName(scopePanel, "protocol");
179+
JComboBox<?> protocolCombo = (JComboBox<?>) findComponentByName(scopePanel, "protocol");
180180
JTextField hostField = (JTextField) findComponentByName(scopePanel, "host");
181181
JTextField pathField = (JTextField) findComponentByName(scopePanel, "path");
182182
JCheckBox useRegexCheck = (JCheckBox) findComponentByName(scopePanel, "useRegex");
183183

184-
String protocol = protocolCombo != null ? (String) protocolCombo.getSelectedItem() : "";
184+
String protocol = protocolCombo != null ? String.valueOf(protocolCombo.getSelectedItem()) : "";
185185
String host = hostField != null ? hostField.getText().trim() : "";
186186
String path = pathField != null ? pathField.getText().trim() : "";
187187
boolean useRegex = useRegexCheck != null && useRegexCheck.isSelected();
@@ -193,11 +193,11 @@ public boolean isCellEditable(int row, int column) {
193193
}
194194

195195
JSpinner ttlSpinner = (JSpinner) findComponentByName(scopePanel, "ttl");
196-
JComboBox<String> strategyCombo = (JComboBox<String>) findComponentByName(scopePanel, "strategy");
196+
JComboBox<?> strategyCombo = (JComboBox<?>) findComponentByName(scopePanel, "strategy");
197197
JSpinner prioritySpinner = (JSpinner) findComponentByName(scopePanel, "priority");
198198

199199
int ttl = ttlSpinner != null ? (Integer) ttlSpinner.getValue() : 3600;
200-
String strategy = strategyCombo != null ? (String) strategyCombo.getSelectedItem() : "REPLACE";
200+
String strategy = strategyCombo != null ? String.valueOf(strategyCombo.getSelectedItem()) : "REPLACE";
201201
int priority = prioritySpinner != null ? (Integer) prioritySpinner.getValue() : 50;
202202

203203
sendSessionHeadersToBackend(selectedHeaders, scopeJson, ttl, strategy, priority);

src/burpEx/montoya-api/src/main/java/com/sqlmapwebui/burp/dialogs/HeaderRuleDialog.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ public boolean isCellEditable(int row, int column) {
123123
dialog.add(contentPanel, BorderLayout.CENTER);
124124

125125
// 从ruleConfigPanel提取组件引用
126-
JTextField namePrefixField = (JTextField) findComponentByName(ruleConfigPanel, "namePrefixField");
127-
JComboBox<String> strategyCombo = (JComboBox<String>) findComponentByName(ruleConfigPanel, "strategyCombo");
128-
JSpinner prioritySpinner = (JSpinner) findComponentByName(ruleConfigPanel, "prioritySpinner");
129-
JCheckBox isActiveCheck = (JCheckBox) findComponentByName(ruleConfigPanel, "isActiveCheck");
130-
JCheckBox enableScopeCheck = (JCheckBox) findComponentByName(ruleConfigPanel, "enableScopeCheck");
131-
JComboBox<String> protocolCombo = (JComboBox<String>) findComponentByName(ruleConfigPanel, "protocolCombo");
132-
JTextField hostField = (JTextField) findComponentByName(ruleConfigPanel, "hostField");
133-
JTextField pathField = (JTextField) findComponentByName(ruleConfigPanel, "pathField");
134-
JCheckBox useRegexCheck = (JCheckBox) findComponentByName(ruleConfigPanel, "useRegexCheck");
126+
JTextField namePrefixField = findComponentByName(ruleConfigPanel, "namePrefixField", JTextField.class);
127+
JComboBox<?> strategyCombo = findComponentByName(ruleConfigPanel, "strategyCombo", JComboBox.class);
128+
JSpinner prioritySpinner = findComponentByName(ruleConfigPanel, "prioritySpinner", JSpinner.class);
129+
JCheckBox isActiveCheck = findComponentByName(ruleConfigPanel, "isActiveCheck", JCheckBox.class);
130+
JCheckBox enableScopeCheck = findComponentByName(ruleConfigPanel, "enableScopeCheck", JCheckBox.class);
131+
JComboBox<?> protocolCombo = findComponentByName(ruleConfigPanel, "protocolCombo", JComboBox.class);
132+
JTextField hostField = findComponentByName(ruleConfigPanel, "hostField", JTextField.class);
133+
JTextField pathField = findComponentByName(ruleConfigPanel, "pathField", JTextField.class);
134+
JCheckBox useRegexCheck = findComponentByName(ruleConfigPanel, "useRegexCheck", JCheckBox.class);
135135

136136
// 底部按钮
137137
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
@@ -298,15 +298,19 @@ private JPanel createRuleConfigPanel(HttpRequest request) {
298298
}
299299

300300
/**
301-
* 根据名称查找组件
301+
* 根据名称和类型安全地查找组件
302+
* @param container 容器
303+
* @param name 组件名称
304+
* @param type 期望的组件类型
305+
* @return 找到的组件,如果未找到或类型不匹配则返回null
302306
*/
303-
private Component findComponentByName(Container container, String name) {
307+
private <T extends Component> T findComponentByName(Container container, String name, Class<T> type) {
304308
for (Component c : container.getComponents()) {
305-
if (name.equals(c.getName())) {
306-
return c;
309+
if (name.equals(c.getName()) && type.isInstance(c)) {
310+
return type.cast(c);
307311
}
308312
if (c instanceof Container) {
309-
Component result = findComponentByName((Container) c, name);
313+
T result = findComponentByName((Container) c, name, type);
310314
if (result != null) return result;
311315
}
312316
}

src/burpEx/montoya-api/src/main/java/com/sqlmapwebui/burp/dialogs/SessionHeaderDialog.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ public boolean isCellEditable(int row, int column) {
133133
dialog.add(contentPanel, BorderLayout.CENTER);
134134

135135
// 从scopePanel提取组件引用
136-
JCheckBox enableScopeCheck = (JCheckBox) findComponentByName(scopePanel, "enableScopeCheck");
137-
JComboBox<String> protocolCombo = (JComboBox<String>) findComponentByName(scopePanel, "protocolCombo");
138-
JTextField hostField = (JTextField) findComponentByName(scopePanel, "hostField");
139-
JTextField pathField = (JTextField) findComponentByName(scopePanel, "pathField");
140-
JCheckBox useRegexCheck = (JCheckBox) findComponentByName(scopePanel, "useRegexCheck");
141-
JSpinner ttlSpinner = (JSpinner) findComponentByName(scopePanel, "ttlSpinner");
142-
JComboBox<String> strategyCombo = (JComboBox<String>) findComponentByName(scopePanel, "strategyCombo");
143-
JSpinner prioritySpinner = (JSpinner) findComponentByName(scopePanel, "prioritySpinner");
136+
JCheckBox enableScopeCheck = findComponentByType(scopePanel, "enableScopeCheck", JCheckBox.class);
137+
JComboBox<?> protocolCombo = findComponentByType(scopePanel, "protocolCombo", JComboBox.class);
138+
JTextField hostField = findComponentByType(scopePanel, "hostField", JTextField.class);
139+
JTextField pathField = findComponentByType(scopePanel, "pathField", JTextField.class);
140+
JCheckBox useRegexCheck = findComponentByType(scopePanel, "useRegexCheck", JCheckBox.class);
141+
JSpinner ttlSpinner = findComponentByType(scopePanel, "ttlSpinner", JSpinner.class);
142+
JComboBox<?> strategyCombo = findComponentByType(scopePanel, "strategyCombo", JComboBox.class);
143+
JSpinner prioritySpinner = findComponentByType(scopePanel, "prioritySpinner", JSpinner.class);
144144

145145
// 底部按钮
146146
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
@@ -164,7 +164,8 @@ public boolean isCellEditable(int row, int column) {
164164

165165
String scopeJson = "null";
166166
if (enableScopeCheck.isSelected()) {
167-
String protocol = (String) protocolCombo.getSelectedItem();
167+
Object protocolObj = protocolCombo.getSelectedItem();
168+
String protocol = protocolObj != null ? protocolObj.toString() : "";
168169
String host = hostField.getText().trim();
169170
String path = pathField.getText().trim();
170171
boolean useRegex = useRegexCheck.isSelected();
@@ -176,7 +177,8 @@ public boolean isCellEditable(int row, int column) {
176177
}
177178

178179
int ttl = (Integer) ttlSpinner.getValue();
179-
String strategy = (String) strategyCombo.getSelectedItem();
180+
Object strategyObj = strategyCombo.getSelectedItem();
181+
String strategy = strategyObj != null ? strategyObj.toString() : "REPLACE";
180182
int priority = (Integer) prioritySpinner.getValue();
181183

182184
sendSessionHeadersToBackend(selectedHeaders, scopeJson, ttl, strategy, priority);
@@ -307,6 +309,21 @@ private Component findComponentByName(Container container, String name) {
307309
return null;
308310
}
309311

312+
/**
313+
* 根据名称和类型安全地查找组件
314+
* @param container 容器
315+
* @param name 组件名称
316+
* @param type 期望的组件类型
317+
* @return 找到的组件,如果未找到或类型不匹配则返回null
318+
*/
319+
private <T extends Component> T findComponentByType(Container container, String name, Class<T> type) {
320+
Component component = findComponentByName(container, name);
321+
if (component != null && type.isInstance(component)) {
322+
return type.cast(component);
323+
}
324+
return null;
325+
}
326+
310327
/**
311328
* 发送会话Header到后端
312329
*/

0 commit comments

Comments
 (0)