Actionable YAML diagnostics for Java applications and plugins.
java-parser-check parses YAML files, validates their structure, and returns clear diagnostics with source locations, error codes, explanations, and repair suggestions. It is designed for configuration-heavy projects where a single YAML mistake can prevent an application or Minecraft plugin from starting.
- Parse YAML from files, readers, or strings
- Report syntax errors with line and column information
- Detect duplicate keys instead of silently accepting the last value
- Reject unsupported multi-document YAML files
- Validate required keys and YAML value types with a small, fluent schema API
- Report warnings for empty documents and unknown schema keys
- Return parsed values as standard Java collections and scalar values
- Use SnakeYAML's safe constructor
- Apply alias and input-size limits to reduce resource-exhaustion risks
- Format diagnostics for logs, build tools, and editor integrations
- Java 8 or newer at runtime
- Gradle 9.7.1 or newer for building (Gradle 9.7.1 itself runs on JDK 17+)
JitPack builds the published GitHub tags and is the easiest way to use the library right now. Add the JitPack repository and the dependency to your project.
repositories {
maven("https://jitpack.io")
}
dependencies {
implementation("com.github.BitAspire:java-parser-check:0.1.1")
}repositories {
maven { url = 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.BitAspire:java-parser-check:0.1.1'
}Replace 0.1.1 with the release tag you want to use. JitPack uses the GitHub owner in the group ID, so the dependency starts with com.github.BitAspire.
Use JPC for the simple case:
import com.bitaspire.javaparsercheck.JPC;
import com.bitaspire.javaparsercheck.diagnostics.DiagnosticReport;
import java.nio.file.Paths;
import java.util.Map;
DiagnosticReport report = JPC.diagnose(Paths.get("plugin.yml"));
if (report.hasErrors()) {
System.err.println(report.format());
return;
}
Map<?, ?> configuration = (Map<?, ?>) report.value().orElseThrow(
() -> new IllegalStateException("Expected a parsed YAML value")
);DiagnosticReport.isValid() returns false when at least one error is present. Warnings do not invalidate the document.
For applications that prefer fail-fast startup:
JPC.diagnose(Paths.get("plugin.yml")).throwIfInvalid();Parsing confirms that a file is valid YAML. A schema confirms that it contains the configuration your application expects.
import com.bitaspire.javaparsercheck.JPC;
import com.bitaspire.javaparsercheck.diagnostics.DiagnosticReport;
import com.bitaspire.javaparsercheck.yaml.YamlOptions;
import com.bitaspire.javaparsercheck.yaml.YamlSchema;
import com.bitaspire.javaparsercheck.yaml.YamlType;
import java.nio.file.Paths;
YamlSchema pluginSchema = YamlSchema.builder()
.required("name", YamlType.STRING)
.required("main", YamlType.STRING)
.required("version", YamlType.STRING)
.optional("api-version", YamlType.STRING)
.optional("depend", YamlType.LIST)
.allowUnknownKeys(false)
.build();
DiagnosticReport report = JPC.diagnose(
Paths.get("plugin.yml"),
YamlOptions.builder()
.schema(pluginSchema)
.build()
);
if (!report.isValid()) {
report.diagnostics().forEach(diagnostic ->
System.err.println(diagnostic.format())
);
}Schemas support:
- required and optional keys
- nested maps
- strict or permissive unknown-key handling
STRINGBOOLEANINTEGERNUMBERLISTMAPNULLANY
JPC.diagnose(Paths.get("config.yml"));
JPC.diagnose(file, options);
JPC.diagnose(reader, "config.yml");
JPC.diagnoseContent(yaml, "config.yml");The source name supplied for readers and strings is included in formatted diagnostics.
Every diagnostic contains:
- severity:
ERROR,WARNING, orINFO - stable diagnostic code
- human-readable message
- optional explanation
- optional repair suggestion
- source range with one-based line and column numbers
Example:
plugin.yml:4:3 [ERROR JPC-YAML-002] Duplicate key 'commands'. YAML mappings should contain each key only once; different loaders may keep different values. Suggestion: Remove the duplicate key or merge its values into the first occurrence.
| Code | Description |
|---|---|
JPC-YAML-001 |
Invalid YAML syntax or a parser/loader limit was reached |
JPC-YAML-002 |
Duplicate mapping key |
JPC-YAML-004 |
More than one YAML document in one file |
JPC-YAML-005 |
Empty YAML document |
JPC-SCHEMA-001 |
Schema expected a map |
JPC-SCHEMA-002 |
Required key is missing |
JPC-SCHEMA-003 |
Value has the wrong YAML type |
JPC-SCHEMA-004 |
Key is not declared in a strict schema |
JPC-IO-001 |
YAML file could not be read |
JPC-IO-002 |
YAML reader could not be read |
- YAML is loaded with SnakeYAML's
SafeConstructor; application classes are not instantiated automatically. - Duplicate keys are reported explicitly. The parsed value is still available so callers can inspect the document, but the report is invalid.
- The default limits are 50 aliases and 3,000,000 code points. Configure them with
YamlOptionswhen needed. - Empty documents produce a warning by default.
- Unknown keys produce warnings when
allowUnknownKeys(false)is enabled.
Publishing a GitHub Release triggers the release workflow. The workflow:
- checks out the released tag
- runs the Java 8-compatible build and tests
- attaches the main, sources, and Javadocs JARs to the GitHub Release
- creates SHA-256 checksums
- requests a JitPack build for the same tag
JitPack also builds tags on demand when a dependency is requested for the first time. Build status is available at:
https://jitpack.io/#BitAspire/java-parser-check/0.1.1
This project is published from the BitAspire/java-parser-check GitHub repository.
repositories {
maven("https://jitpack.io")
}
dependencies {
implementation("com.github.BitAspire:java-parser-check:0.1.1")
}JitPack uses the GitHub owner as the group, so the dependency is com.github.BitAspire rather than the library's regular Maven group com.bitaspire.
gradle testThe library targets Java 8 and uses Gradle 9.7.1 for builds. Gradle 9.7.1 itself runs on JDK 17+. To generate the standard Gradle wrapper for local development:
gradle wrapper --gradle-version 9.7.1
./gradlew testContributions are welcome. See CONTRIBUTING.md for development setup, testing guidance, feature proposals, and pull request guidelines.
This project is licensed under the Apache License 2.0.