Class YmlSecurityException

All Implemented Interfaces:
Serializable

public class YmlSecurityException extends OpenYmlException
YAML Security Exception - Thrown when security violation is detected YAML 安全异常 - 当检测到安全违规时抛出

This exception is thrown when YAML content violates security constraints.

当 YAML 内容违反安全约束时抛出此异常。

Features | 主要功能:

  • Categorized violation types (alias, depth, size, type, recursion) - 分类违规类型(别名、深度、大小、类型、递归)
  • Factory methods for common security violations - 常见安全违规的工厂方法
  • Error code YML_SECURITY_001 - 错误码 YML_SECURITY_001

Usage Examples | 使用示例:

try {
    YmlSecurity.validate(yamlContent);
} catch (YmlSecurityException e) {
    System.err.println("Violation: " + e.getType());
}

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 线程安全: 是(构建后不可变)
  • Null-safe: No (type must not be null) - 空值安全: 否(类型不能为空)
Since:
JDK 25, opencode-base-yml V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • YmlSecurityException

      public YmlSecurityException(YmlSecurityException.SecurityViolationType type, String message)
      Constructs a security exception with type and message. 构造带类型和消息的安全异常。
      Parameters:
      type - the violation type | 违规类型
      message - the detail message | 详细消息
    • YmlSecurityException

      public YmlSecurityException(YmlSecurityException.SecurityViolationType type, String message, Throwable cause)
      Constructs a security exception with type, message and cause. 构造带类型、消息和原因的安全异常。
      Parameters:
      type - the violation type | 违规类型
      message - the detail message | 详细消息
      cause - the cause | 原因
  • Method Details

    • getType

      Gets the security violation type. 获取安全违规类型。
      Returns:
      the violation type | 违规类型
    • aliasLimitExceeded

      public static YmlSecurityException aliasLimitExceeded(int count, int limit)
      Creates an exception for alias limit exceeded. 为别名超限创建异常。
      Parameters:
      count - the alias count | 别名数量
      limit - the alias limit | 别名限制
      Returns:
      the exception | 异常
    • nestingDepthExceeded

      public static YmlSecurityException nestingDepthExceeded(int depth, int limit)
      Creates an exception for nesting depth exceeded. 为嵌套深度超限创建异常。
      Parameters:
      depth - the nesting depth | 嵌套深度
      limit - the depth limit | 深度限制
      Returns:
      the exception | 异常
    • documentSizeExceeded

      public static YmlSecurityException documentSizeExceeded(long size, long limit)
      Creates an exception for document size exceeded. 为文档大小超限创建异常。
      Parameters:
      size - the document size | 文档大小
      limit - the size limit | 大小限制
      Returns:
      the exception | 异常
    • forbiddenType

      public static YmlSecurityException forbiddenType(String typeName)
      Creates an exception for forbidden type. 为禁止类型创建异常。
      Parameters:
      typeName - the forbidden type name | 禁止的类型名称
      Returns:
      the exception | 异常
    • unsafeType

      public static YmlSecurityException unsafeType(String typeName)
      Creates an exception for unsafe type. 为不安全类型创建异常。
      Parameters:
      typeName - the unsafe type name | 不安全的类型名称
      Returns:
      the exception | 异常