Class SandboxException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.core.exception.OpenException
cloud.opencode.base.expression.OpenExpressionException
cloud.opencode.base.expression.sandbox.SandboxException
- All Implemented Interfaces:
Serializable
Sandbox Exception
沙箱异常
Thrown when a security violation is detected during expression evaluation.
在表达式求值过程中检测到安全违规时抛出。
Features | 主要功能:
- Typed violation categories via ViolationType enum - 通过ViolationType枚举的类型化违规分类
- Violated resource tracking - 被违规资源跟踪
- Static factory methods for common violations - 常见违规的静态工厂方法
Usage Examples | 使用示例:
try {
OpenExpression.eval("Runtime.exec('cmd')", sandboxedCtx);
} catch (SandboxException e) {
SandboxException.ViolationType type = e.getViolationType();
String resource = e.getViolatedResource();
}
// Create specific violations
throw SandboxException.classNotAllowed("java.lang.Runtime");
throw SandboxException.methodNotAllowed("exec");
Security | 安全性:
- Thread-safe: Yes, immutable after construction - 线程安全: 是,构造后不可变
- Null-safe: Yes, null resource handled gracefully - 空值安全: 是,null资源优雅处理
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumViolation Type Enum 违规类型枚举 -
Constructor Summary
ConstructorsConstructorDescriptionSandboxException(String message) Create sandbox exception 创建沙箱异常SandboxException(String message, SandboxException.ViolationType violationType, String violatedResource) Create sandbox exception with violation type 创建带违规类型的沙箱异常SandboxException(String message, Throwable cause) Create sandbox exception with cause 创建带原因的沙箱异常 -
Method Summary
Modifier and TypeMethodDescriptionstatic SandboxExceptionclassNotAllowed(Class<?> clazz) Create exception for denied class access 创建拒绝类访问的异常static SandboxExceptionclassNotAllowed(String className) Create exception for denied class access 创建拒绝类访问的异常static SandboxExceptiondepthLimitExceeded(int maxDepth) Create exception for depth limit exceeded 创建深度限制超出异常static SandboxExceptionexpressionTooLong(int maxLength, int actualLength) Create exception for expression length exceeded 创建表达式长度超出异常static SandboxExceptionfunctionNotAllowed(String functionName) Create exception for denied function access 创建拒绝函数访问的异常Get the violated resource 获取被违规的资源Get the violation type 获取违规类型static SandboxExceptioniterationLimitExceeded(int maxIterations) Create exception for iteration limit exceeded 创建迭代限制超出异常static SandboxExceptionmethodNotAllowed(String methodName) Create exception for denied method access 创建拒绝方法访问的异常static SandboxExceptionmethodNotAllowed(String className, String methodName) Create exception for denied method access with class context 创建带类上下文的拒绝方法访问异常static SandboxExceptionpropertyNotAllowed(String propertyName) Create exception for denied property access 创建拒绝属性访问的异常static SandboxExceptiontimeout(long timeoutMs) Create exception for execution timeout 创建执行超时异常Methods inherited from class OpenExpressionException
divisionByZero, evaluationError, evaluationError, functionNotFound, getExpression, getPosition, methodNotFound, nullPointer, parseError, parseError, propertyNotFound, securityViolation, typeErrorMethods inherited from class OpenException
getComponent, getErrorCode, getMessage, getRawMessageMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
SandboxException
Create sandbox exception 创建沙箱异常- Parameters:
message- the error message | 错误消息
-
SandboxException
public SandboxException(String message, SandboxException.ViolationType violationType, String violatedResource) Create sandbox exception with violation type 创建带违规类型的沙箱异常- Parameters:
message- the error message | 错误消息violationType- the violation type | 违规类型violatedResource- the violated resource | 被违规的资源
-
SandboxException
-
-
Method Details
-
getViolationType
Get the violation type 获取违规类型- Returns:
- the violation type | 违规类型
-
getViolatedResource
Get the violated resource 获取被违规的资源- Returns:
- the violated resource | 被违规的资源
-
classNotAllowed
Create exception for denied class access 创建拒绝类访问的异常- Parameters:
className- the class name | 类名- Returns:
- the exception | 异常
-
classNotAllowed
Create exception for denied class access 创建拒绝类访问的异常- Parameters:
clazz- the class | 类- Returns:
- the exception | 异常
-
methodNotAllowed
Create exception for denied method access 创建拒绝方法访问的异常- Parameters:
methodName- the method name | 方法名- Returns:
- the exception | 异常
-
methodNotAllowed
Create exception for denied method access with class context 创建带类上下文的拒绝方法访问异常- Parameters:
className- the class name | 类名methodName- the method name | 方法名- Returns:
- the exception | 异常
-
propertyNotAllowed
Create exception for denied property access 创建拒绝属性访问的异常- Parameters:
propertyName- the property name | 属性名- Returns:
- the exception | 异常
-
functionNotAllowed
Create exception for denied function access 创建拒绝函数访问的异常- Parameters:
functionName- the function name | 函数名- Returns:
- the exception | 异常
-
timeout
Create exception for execution timeout 创建执行超时异常- Parameters:
timeoutMs- the timeout in milliseconds | 超时毫秒数- Returns:
- the exception | 异常
-
iterationLimitExceeded
Create exception for iteration limit exceeded 创建迭代限制超出异常- Parameters:
maxIterations- the max iterations | 最大迭代次数- Returns:
- the exception | 异常
-
expressionTooLong
Create exception for expression length exceeded 创建表达式长度超出异常- Parameters:
maxLength- the max length | 最大长度actualLength- the actual length | 实际长度- Returns:
- the exception | 异常
-
depthLimitExceeded
Create exception for depth limit exceeded 创建深度限制超出异常- Parameters:
maxDepth- the max depth | 最大深度- Returns:
- the exception | 异常
-