{"record":{"id":"82f7748a33bab7a8","repo":"apache/beam","slug":"malformed-s-class-s-timer-declaration-field-s-is-not","errorCode":null,"errorMessage":"Malformed %s class %s: timer declaration field %s is not accessible.","messagePattern":"Malformed (.+?) class (.+?): timer declaration field (.+?) is not accessible\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnSignatures.java","lineNumber":2555,"sourceCode":"              format(DoFn.class), target.getClass().getName(), stateDeclaration.field().getName()));\n    }\n  }\n\n  public static TimerSpec getTimerSpecOrThrow(\n      TimerDeclaration timerDeclaration, DoFn<?, ?> target) {\n    try {\n      Object fieldValue = timerDeclaration.field().get(target);\n      checkState(\n          fieldValue instanceof TimerSpec,\n          \"Malformed %s class %s: timer declaration field %s does not have type %s.\",\n          format(DoFn.class),\n          target.getClass().getName(),\n          timerDeclaration.field().getName(),\n          TimerSpec.class);\n\n      return (TimerSpec) timerDeclaration.field().get(target);\n    } catch (IllegalAccessException exc) {\n      throw new RuntimeException(\n          String.format(\n              \"Malformed %s class %s: timer declaration field %s is not accessible.\",\n              format(DoFn.class), target.getClass().getName(), timerDeclaration.field().getName()));\n    }\n  }\n\n  public static TimerSpec getTimerFamilySpecOrThrow(\n      TimerFamilyDeclaration timerFamilyDeclaration, DoFn<?, ?> target) {\n    try {\n      Object fieldValue = timerFamilyDeclaration.field().get(target);\n      checkState(\n          fieldValue instanceof TimerSpec,\n          \"Malformed %s class %s: timer declaration field %s does not have type %s.\",\n          format(DoFn.class),\n          target.getClass().getName(),\n          timerFamilyDeclaration.field().getName(),\n          TimerSpec.class);\n","sourceCodeStart":2537,"sourceCodeEnd":2573,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnSignatures.java#L2537-L2573","documentation":"Beam reads a DoFn's @TimerId-decorated field reflectively to obtain its TimerSpec. If the field cannot be accessed (IllegalAccessException from Field.get), Beam throws a RuntimeException saying the DoFn class is malformed because the timer declaration field is not accessible.","triggerScenarios":"Declaring a @TimerId field that is private/protected/package-private, then invoking a pipeline that triggers getTimerSpec via reflection, so timerDeclaration.field().get(target) throws IllegalAccessException.","commonSituations":"Private timer fields written by developers used to encapsulation; code reviews/suppressing warnings pushing fields to private; copy-pasting state fields pattern but applying wrong access to timer fields.","solutions":["Make the @TimerId field public","Verify the field is of type TimerSpec (e.g. TimerSpecs.timer(...)) and lives directly on the DoFn","Ensure the DoFn class and field are accessible to Beam's reflection code","Re-run pipeline construction; error will disappear once reflection succeeds"],"exampleFix":"// before\n@TimerId(\"alarm\")\nprivate final TimerSpec alarmSpec = TimerSpecs.timer(TimeDomain.EVENT_TIME);\n\n// after\n@TimerId(\"alarm\")\npublic final TimerSpec alarmSpec = TimerSpecs.timer(TimeDomain.EVENT_TIME);","handlingStrategy":"validation","validationCode":"for (Field f : MyFn.class.getDeclaredFields()) {\n  if (f.isAnnotationPresent(TimerId.class) && !Modifier.isPublic(f.getModifiers())) {\n    throw new IllegalStateException(\"@TimerId field must be public: \" + f.getName());\n  }\n}","typeGuard":"static boolean isAccessibleTimerField(Field f) {\n  return Modifier.isPublic(f.getModifiers()) && f.getType() == TimerSpec.class;","tryCatchPattern":"try {\n  pipeline.run();\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"timer declaration field\")) {\n    // widen the field's visibility to public\n  }\n}","preventionTips":["Make all @TimerId fields public final","Keep timer specs on the DoFn class itself, not superclasses","Lint check: annotation-decorated fields should never be private in Beam DoFns"],"tags":["java","apache-beam","reflection","timer-api","illegal-access"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}