{"record":{"id":"9de3b6c7e117fd97","repo":"apple/pkl","slug":"cannot-call-both-setsecuritymanager-and-setallo-9de3b6","errorCode":null,"errorMessage":"Cannot call both `setSecurityManager` and `setAllowedResources`, because both define security manager settings.","messagePattern":"Cannot call both `setSecurityManager` and `setAllowedResources`, because both define security manager settings\\.","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java","lineNumber":220,"sourceCode":"          \"Cannot call both `setSecurityManager` and `setAllowedModules`, because both define security manager settings.\");\n    }\n    securityManagerBuilder.setAllowedModules(patterns);\n    return this;\n  }\n\n  /** Returns the set of patterns to be allowed when importing modules. */\n  public List<Pattern> getAllowedModules() {\n    return securityManagerBuilder.getAllowedModules();\n  }\n\n  /**\n   * Sets the set of URI patterns to be allowed when reading resources.\n   *\n   * @throws IllegalStateException if {@link #setSecurityManager(SecurityManager)} was also called.\n   */\n  public EvaluatorBuilder setAllowedResources(Collection<Pattern> patterns) {\n    if (securityManager != null) {\n      throw new IllegalStateException(\n          \"Cannot call both `setSecurityManager` and `setAllowedResources`, because both define security manager settings.\");\n    }\n    securityManagerBuilder.setAllowedResources(patterns);\n    return this;\n  }\n\n  /** Returns the set of patterns to be allowed when reading resources. */\n  public List<Pattern> getAllowedResources() {\n    return securityManagerBuilder.getAllowedResources();\n  }\n\n  /**\n   * Sets the root directory, which restricts access to file-based modules and resources located\n   * under this directory.\n   */\n  public EvaluatorBuilder setRootDir(@Nullable Path rootDir) {\n    securityManagerBuilder.setRootDir(rootDir);\n    return this;","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java#L202-L238","documentation":"Guard in EvaluatorBuilder.setAllowedResources: throws IllegalStateException when setSecurityManager has already been called. Resource-read rules would then be defined twice — by the custom SecurityManager and by the allowed-resource patterns — so the builder rejects the ambiguous configuration.","triggerScenarios":"Thrown at pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java:220 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the resource allow-list into the custom SecurityManager and do not call setAllowedResources.","Skip setSecurityManager and configure resource access with setAllowedResources only."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}