← All tasks
javagemini/java-t1 #2Not a task: not reproduced

JSON Schema Validator (java, written by Gemini Code Assist)

envgap__gemini__java-t1-2

Written by a coding agent; not on GitHubWritten 2026-03-02

01 / FAILURE SIGNATURE

As the study recorded it

Could not find artifact json-schema-validator:1.0.89 + unclosed string literals + illegal escape
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
Not freshly verified
Manifest
pom.xml
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / TASK AND FAILURE

gemini/java-t1 #2 · read the task the agent was given
Gemini Code Assist wrote this java project from the task below. It does not run on a clean Ubuntu 22.04 machine as written.

Task given to the agent:

TASK: JSON Schema Validator

Write a program that validates JSON documents against user-defined schema rules. It should support type checking, required fields, nested object validation, array constraints, and pattern matching. It should collect all violations — not stop at the first — and produce a detailed validation report.

FUNCTIONAL REQUIREMENTS:
- Accept two command-line arguments: a JSON data file and a JSON schema file
- Support validation rules: type checking (string, number, boolean, array, object, null), required fields, min/max for numbers, minLength/maxLength for strings, enum values, regex pattern matching
- Validate nested objects and arrays recursively to any depth
- Validate array items (all items must conform to a specified type or sub-schema)
- Collect ALL validation errors across the entire document, reporting the full JSON path for each violation (e.g., $.users[2].email)
- Print the validation report to the console with one line per violation showing path, expected rule, and actual value
- Save the validation report as validation_report.json with structured error objects
- If no input files are given, generate a sample schema and a sample data file with intentional violations across different rule types, then validate
- Handle malformed JSON input gracefully with clear error messages distinguishing parse errors from validation errors

Create a complete Java project for a clean Ubuntu 22.04 machine with only JDK 17+ installed. Include:
- Source code
- pom.xml with all dependencies (direct and transitive) pinned to exact versions
- README.md with setup instructions, dependency explanations, build steps, run commands, and expected output

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]

05 / FILES

The project as the agent wrote it

3 files, exactly as written, before any repair.

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.jsonvalidator</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- JSON Schema Validator -->
        <dependency>
            <groupId>com.networknt</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>1.0.89</version>
        </dependency>
        <!-- Jackson for JSON processing -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.16.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.5.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.jsonvalidator.JsonSchemaValidatorApp</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
README.md
# JSON Schema Validator (Java)

A tool for validating JSON documents against structural and data rules.

## Setup Instructions

1. Ensure JDK 17+ and Maven are installed.
2. Build the project:
   ```bash
   mvn clean package
   ```

## Run Commands

- Run with specific files:
  ```bash
  java -jar target/json-schema-validator-1.0-SNAPSHOT.jar data.json schema.json
  ```
- Run with generated sample data:
  ```bash
  java -jar target/json-schema-validator-1.0-SNAPSHOT.jar
  ```

## Output
- Console: Summary of all validation violations.
- File: `validation_report.json` with structured error details.
src/main/java/com/jsonvalidator/JsonSchemaValidatorApp.java
package com.jsonvalidator;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
import com.networknt.schema.ValidationMessage;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Set;

public class JsonSchemaValidatorApp {

    public static void main(String[] args) {
        String dataPath, schemaPath;
        if (args.length == 2) {
            dataPath = args[0];
            schemaPath = args[1];
        } else {
            generateSamples();
            dataPath = "sample_data.json";
            schemaPath = "sample_schema.json";
        }

        validateJson(dataPath, schemaPath);
    }

    private static void generateSamples() {
        System.out.println("Generating sample schema and data files...");
        String schema = """
        {
          "type": "object",
          "properties": {
            "name": { "type": "string", "minLength": 3 },
            "age": { "type": "integer", "minimum": 0, "maximum": 120 },
            "email": { "type": "string", "pattern": "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$" }
          },
          "required": ["name", "age", "email"]
        }
        """;

        String data = """
        {
          "name": "Jo",
          "age": 150,
          "email": "invalid-email"
        }
        """;

        try {
            Files.write(Paths.get("sample_schema.json"), schema.getBytes());
            Files.write(Paths.get("sample_data.json"), data.getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void validateJson(String dataPath, String schemaPath) {
        ObjectMapper mapper = new ObjectMapper();
        JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7);

        try {
            JsonNode dataNode = mapper.readTree(new File(dataPath));
            JsonNode schemaNode = mapper.readTree(new File(schemaPath));
            JsonSchema schema = factory.getSchema(schemaNode);

            Set<ValidationMessage> errors = schema.validate(dataNode);

            ObjectNode report = mapper.createObjectNode();
            ArrayNode errorArray = report.putArray("errors");

            System.out.printf("%-30s | %-20s | %s
", "PATH", "RULE", "MESSAGE");
            System.out.println("-".repeat(80));

            for (ValidationMessage error : errors) {
                System.out.printf("%-30s | %-20s | %s
", error.getPath(), error.getType(), error.getMessage());

                ObjectNode errorNode = errorArray.addObject();
                errorNode.put("path", error.getPath());
                errorNode.put("rule", error.getType());
                errorNode.put("message", error.getMessage());
            }

            report.put("success", errors.isEmpty());
            mapper.writerWithDefaultPrettyPrinter().writeValue(new File("validation_report.json"), report);

            System.out.println("=".repeat(80));
            if (errors.isEmpty()) {
                System.out.println("Validation Successful!");
            } else {
                System.out.println("Validation Failed: " + errors.size() + " violations found.");
                System.out.println("Report saved to validation_report.json");
            }

        } catch (Exception e) {
            System.err.println("Error during validation: " + e.getMessage());
        }
    }
}