{"record":{"id":"15158e63259a35c9","repo":"apache/pulsar","slug":"schema-should-not-be-null","errorCode":null,"errorMessage":"Schema should not be null.","messagePattern":"Schema should not be null\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/utils/FunctionRecord.java","lineNumber":63,"sourceCode":"        /**\n         * Force to use {@link #from(Context, Schema)}.\n         */\n        private FunctionRecordBuilder() {}\n    }\n\n    /**\n     * Creates a builder for a Record from a Function Context.\n     * The builder is initialized with the output topic from the Context and with the topicName, key, eventTime,\n     * properties, partitionId, partitionIndex and recordSequence from the Context input Record.\n     * It doesn't initialize a Message at the moment.\n     *\n     * @param context a Function Context\n     * @param <T> type of Record to build\n     * @return a Record builder initialised with values from the Function Context\n     */\n    public static <T> FunctionRecord.FunctionRecordBuilder<T> from(Context context, Schema<T> schema) {\n        if (schema == null) {\n            throw new IllegalArgumentException(\"Schema should not be null.\");\n        }\n        Record<?> currentRecord = context.getCurrentRecord();\n        FunctionRecordBuilder<T> builder = new FunctionRecordBuilder<T>()\n            .schema(schema)\n            .destinationTopic(context.getOutputTopic())\n            .properties(currentRecord.getProperties());\n        currentRecord.getTopicName().ifPresent(builder::topicName);\n        currentRecord.getKey().ifPresent(builder::key);\n        currentRecord.getEventTime().ifPresent(builder::eventTime);\n        currentRecord.getPartitionId().ifPresent(builder::partitionId);\n        currentRecord.getPartitionIndex().ifPresent(builder::partitionIndex);\n        currentRecord.getRecordSequence().ifPresent(builder::recordSequence);\n\n        return builder;\n    }\n\n    @Override\n    public T getValue() {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/utils/FunctionRecord.java#L45-L81","documentation":"FunctionRecord.from(context, schema) builds a Record for output from the current function context. The schema is mandatory because the output record must know how to serialize its value; passing null is rejected with IllegalArgumentException.","triggerScenarios":"Calling FunctionRecord.from(ctx, null), e.g. when a schema variable is conditionally unset, or calling the overload without a schema expecting defaults.","commonSituations":"Refactoring functions that changed from typed to schema-less output, generics erasing the schema selection, or copying example code that relied on a later builder.schema(...) call.","solutions":["Pass an explicit schema, e.g. Schema.STRING, Schema.AVRO(MyPojo.class), or Schema.JSON(MyPojo.class)","If the schema is dynamic, resolve it before calling from() and fail early with a clear message","Use the schema inferred for your type rather than null"],"exampleFix":"// before\nFunctionRecord.from(context, null); // throws\n// after\nFunctionRecord.from(context, Schema.JSON(MyPojo.class));","handlingStrategy":"validation","validationCode":"if (schema == null) {\n    throw new IllegalArgumentException(\"schema must be provided before FunctionRecord.from()\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    builder = FunctionRecord.from(context, schema);\n} catch (IllegalArgumentException e) {\n    builder = FunctionRecord.from(context, Schema.STRING);\n}","preventionTips":["Always resolve the schema before building the output record","Use type-inferred schemas (Schema.JSON/X.class) instead of nullable variables","Add asserts in shared helpers that schema != null"],"tags":["java","pulsar-functions","schema","illegal-argument"],"backgroundTag":"schema-validation-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}