deeplearning4j/deeplearning4j · error · IllegalStateException

Cannot build Join: left and/or right schemas are null

Error message

Cannot build Join: left and/or right schemas are null

What it means

Join.Builder.build() refuses to construct a Join when either the left or right Schema was never set via setLeftSchema/setRightSchema, throwing this IllegalStateException. It is a fail-fast guard so an unusable Join object is never created.

Solutions

  1. Add setLeftSchema(schema) and setRightSchema(schema) before build()
  2. Null-check the schema variables before starting the builder
  3. If schemas are inferred from data, verify the source data is non-empty/non-null

Example fix

// before
Join join = new Join.Builder(Join.JoinType.Inner)
    .setJoinColumnsLeft("userId")
    .setJoinColumnsRight("userId")
    .build();
// after
Join join = new Join.Builder(Join.JoinType.Inner)
    .setLeftSchema(leftSchema)
    .setRightSchema(rightSchema)
    .setJoinColumnsLeft("userId")
    .setJoinColumnsRight("userId")
    .build();
Defensive patterns

Strategy: validation

Validate before calling

if (leftSchema == null || rightSchema == null)
    throw new IllegalStateException("Schemas must be set before Join.builder().build()");

Try / catch

try {
    Join join = builder.build();
} catch (IllegalStateException e) {
    if (e.getMessage().contains("left and/or right schemas are null")) {
        // re-run schema setup
    }
}

Prevention

When it happens

Trigger: Calling new Join.Builder(JoinType.Inner).setJoinColumnsLeft(...).setJoinColumnsRight(...).build() while omitting the setLeftSchema() and/or setRightSchema() calls.

Common situations: Copy-pasting builder code and deleting the schema lines, building a Join programmatically where one schema comes from a possibly-null variable (e.g., failed schema inference from an empty CSV).

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/9e248c47501587e3. Report an issue: GitHub.

Appendix: source

Thrown at datavec/datavec-api/src/main/java/org/datavec/api/transform/join/Join.java:173

         */
        public Builder setJoinColumnsLeft(String... joinColumnNames) {
            this.joinColumnsLeft = joinColumnNames;
            return this;
        }

        /**
         * Specify the names of the columns to join on, for the right data)
         * The idea: join examples where firstDataValues(joinColumNamesLeft[i]) == secondDataValues(joinColumnNamesRight[i]) for all i
         * @param joinColumnNames Names of the columns to join on (for left data)
         */
        public Builder setJoinColumnsRight(String... joinColumnNames) {
            this.joinColumnsRight = joinColumnNames;
            return this;
        }

        public Join build() {
            if (leftSchema == null || rightSchema == null)
                throw new IllegalStateException("Cannot build Join: left and/or right schemas are null");
            return new Join(this);
        }
    }



    public Schema getOutputSchema() {
        if (leftSchema == null)
            throw new IllegalStateException("Left schema is not set (null)");
        if (rightSchema == null)
            throw new IllegalStateException("Right schema is not set (null)");
        if (joinColumnsLeft == null)
            throw new IllegalStateException("Left key columns are not set (null)");
        if (joinColumnsRight == null)
            throw new IllegalArgumentException("Right key columns are not set (null");

        //Approach here: take the left schema, plus the right schema (excluding the key columns from the right schema)
        List<ColumnMetaData> metaDataOut = new ArrayList<>(leftSchema.getColumnMetaData());

View on GitHub (pinned to 4c22ac5fe4)