{"record":{"id":"89b8b7b1e7d18e65","repo":"apache/beam","slug":"name-not-set","errorCode":null,"errorMessage":"name not set","messagePattern":"name not set","errorType":"exception","errorClass":"java.lang.IllegalStateException","httpStatus":null,"severity":"warning","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/values/PValueBase.java","lineNumber":51,"sourceCode":" * PValue}.\n */\n@Internal\npublic abstract class PValueBase implements PValue {\n\n  private final transient @Nullable Pipeline pipeline;\n\n  /**\n   * Returns the name of this {@link PValueBase}.\n   *\n   * <p>By default, the name of a {@link PValueBase} is based on the name of the {@link PTransform}\n   * that produces it. It can be specified explicitly by calling {@link #setName}.\n   *\n   * @throws IllegalStateException if the name hasn't been set yet\n   */\n  @Override\n  public String getName() {\n    if (name == null) {\n      throw new IllegalStateException(\"name not set\");\n    }\n    return name;\n  }\n\n  /**\n   * Sets the name of this {@link PValueBase}. Returns {@code this}.\n   *\n   * @throws IllegalStateException if this {@link PValueBase} has already been finalized and may no\n   *     longer be set.\n   */\n  public PValueBase setName(String name) {\n    checkState(!finishedSpecifying, \"cannot change the name of %s once it's been used\", this);\n    this.name = name;\n    return this;\n  }\n\n  /////////////////////////////////////////////////////////////////////////////\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/values/PValueBase.java#L33-L69","documentation":"PValueBase.getName() throws IllegalStateException when the PValue's name has never been assigned. Every PTransform/PCollection has a name that Beam sets during pipeline construction; querying it before naming (or after constructing a bare PValue) fails. Frequently surfaced indirectly through toString().","triggerScenarios":"Calling getName() (or toString()/display data paths that call it) on a PValue created outside a normal apply() chain, or before the pipeline has assigned the name (name == null).","commonSituations":"Debug logging that calls pvalue.toString() on a hand-constructed PCollection/PValue in tests; building custom PValues without calling setName(); inspecting values before pipeline assembly completes.","solutions":["Ensure the value comes from pipeline.apply(...) so Beam assigns a default name.","Call setName(...) explicitly on the PValue before using getName().","In logging, guard with try-catch or print the class identity instead of relying on getName().","For custom sources/sinks, invoke setName in the constructor or builder."],"exampleFix":"// before\nPCollection<Integer> pc = new PCollection<>(...);\nSystem.out.println(pc.getName()); // IllegalStateException: name not set\n// after\nPCollection<Integer> pc = new PCollection<>(...);\npc.setName(\"my-collection\");\nSystem.out.println(pc.getName());","handlingStrategy":"try-catch","validationCode":"if (pvalue instanceof PValueBase) {\n  try { ((PValueBase) pvalue).getName(); } catch (IllegalStateException e) { /* unnamed */ }\n}","typeGuard":"static boolean hasName(PValue v) {\n  try { v.getName(); return true; } catch (IllegalStateException e) { return false; }\n}","tryCatchPattern":"try {\n  log(name.getName());\n} catch (IllegalStateException e) {\n  log(\"<unnamed>\" + name.getClass().getSimpleName());\n}","preventionTips":["Create PCollections via pipeline.apply() so names are assigned automatically.","Call setName() for hand-built PValues.","Avoid logging getName() during pipeline construction; guard with try-catch."],"tags":["java","apache-beam","illegal-state","naming"],"backgroundTag":"invalid-state-transition","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"}