{"record":{"id":"d78f18c4ed140547","repo":"zaproxy/zaproxy","slug":"ascan-policy-warn-readonly","errorCode":null,"errorMessage":"ascan.policy.warn.readonly","messagePattern":"ascan\\.policy\\.warn\\.readonly","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"zap/src/main/java/org/zaproxy/zap/extension/ascan/PolicyAllCategoryPanel.java","lineNumber":572,"sourceCode":"        if (newName.length() == 0) {\n            getPolicyName().requestFocusInWindow();\n            throw new Exception(Constant.messages.getString(\"ascan.policy.warn.noname\"));\n        } else if (!extension.getPolicyManager().isLegalPolicyName(newName)) {\n            getPolicyName().requestFocusInWindow();\n            throw new Exception(\n                    Constant.messages.getString(\n                            \"ascan.policy.warn.badname\", PolicyManager.ILLEGAL_POLICY_NAME_CHRS));\n\n        } else if (!newName.equals(currentName)) {\n            // Name changed\n            if (extension.getPolicyManager().getAllPolicyNames().stream()\n                    .anyMatch(newName::equalsIgnoreCase)) {\n                getPolicyName().requestFocusInWindow();\n                throw new Exception(Constant.messages.getString(\"ascan.policy.warn.exists\"));\n            }\n        }\n        if (policy.isReadOnly() && newName.equals(currentName)) {\n            throw new Exception(Constant.messages.getString(\"ascan.policy.warn.readonly\"));\n        }\n    }\n\n    @Override\n    public void saveParam(Object obj) throws Exception {\n        this.policy.setName(getPolicyName().getText());\n        if (locked != null) {\n            policy.setLocked(locked.isSelected());\n        }\n    }\n\n    /**\n     * This method initializes jScrollPane\n     *\n     * @return javax.swing.JScrollPane\n     */\n    private JScrollPane getJScrollPane() {\n        if (jScrollPane == null) {","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/zaproxy/zaproxy/blob/9d1970a436b1b189bfb588fc88864c80d9baf6a5/zap/src/main/java/org/zaproxy/zap/extension/ascan/PolicyAllCategoryPanel.java#L554-L590","documentation":"Read-only (built-in default) scan policies cannot be renamed; validateParam throws the localized 'ascan.policy.warn.readonly' message ('Policy is read-only') when the policy isReadOnly() and the name is left unchanged, blocking a save that would attempt to mutate it.","triggerScenarios":"Opening a built-in/default policy in the policy dialog and pressing OK (or attempting save) without changing the name - the dialog tries to save a read-only policy.","commonSituations":"Browsing the Default Policy tab and clicking OK; scripts or add-ons programmatically validating a read-only policy via the panel; attempting to modify default policies shipped with ZAP.","solutions":["Duplicate the policy under a new name and modify the copy instead of the read-only default.","Do not save read-only policies; cancel the dialog unless you actually renamed it.","In code, check policy.isReadOnly() before invoking save/validation paths."],"exampleFix":"// before\nif (panel.getPolicy().isReadOnly()) panel.saveParam(panel.getPolicy()); // throws\n// after\nif (!panel.getPolicy().isReadOnly()) panel.saveParam(panel.getPolicy());","handlingStrategy":"validation","validationCode":"if (policy.isReadOnly()) { /* duplicate first */\n  ScanPolicy copy = new ScanPolicy(new File(dir, newName + \".policy\"));\n  copy.setName(newName); policyManager.savePolicy(copy); return;\n}","typeGuard":null,"tryCatchPattern":"try { panel.saveParam(obj); } catch (Exception e) { if (e.getMessage().startsWith(\"ascan.policy.warn.readonly\")) { /* cancel or offer duplicate */ } }","preventionTips":["Check policy.isReadOnly() before enabling Save in UI or scripts","Duplicate built-in policies before modifying them","Never persist changes to default policies shipped with ZAP"],"tags":["zap","scan-policy","read-only","ui-validation"],"backgroundTag":"read-only-resource-modification","analyzedSha":"9d1970a436b1b189bfb588fc88864c80d9baf6a5","analyzedAt":"2026-09-05T19:26:59.356Z","contentChangedAt":"2026-09-05T19:26:59.356Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}