{"record":{"id":"8e5cf7d48ea7af8d","repo":"apache/beam","slug":"illegal-project-name-specified-in-pubsub-subscription","errorCode":null,"errorMessage":"Illegal project name specified in Pubsub subscription: {project}","messagePattern":"Illegal project name specified in Pubsub subscription: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubIO.java","lineNumber":233,"sourceCode":"\n  private static final Pattern PUBSUB_NAME_REGEXP = Pattern.compile(\"[a-zA-Z][-._~%+a-zA-Z0-9]+\");\n\n  static final int PUBSUB_MESSAGE_MAX_TOTAL_SIZE = 10_000_000;\n\n  private static final int PUBSUB_NAME_MIN_LENGTH = 3;\n  private static final int PUBSUB_NAME_MAX_LENGTH = 255;\n\n  private static final String SUBSCRIPTION_RANDOM_TEST_PREFIX = \"_random/\";\n  private static final String SUBSCRIPTION_STARTING_SIGNAL = \"_starting_signal/\";\n  private static final String TOPIC_DEV_NULL_TEST_NAME = \"/topics/dev/null\";\n\n  public static final String ENABLE_CUSTOM_PUBSUB_SINK = \"enable_custom_pubsub_sink\";\n  public static final String ENABLE_CUSTOM_PUBSUB_SOURCE = \"enable_custom_pubsub_source\";\n\n  private static void validateProjectName(String project) {\n    Matcher match = PROJECT_ID_REGEXP.matcher(project);\n    if (!match.matches()) {\n      throw new IllegalArgumentException(\n          \"Illegal project name specified in Pubsub subscription: \" + project);\n    }\n  }\n\n  private static void validatePubsubName(String name) {\n    if (name.length() < PUBSUB_NAME_MIN_LENGTH) {\n      throw new IllegalArgumentException(\n          \"Pubsub object name is shorter than 3 characters: \" + name);\n    }\n    if (name.length() > PUBSUB_NAME_MAX_LENGTH) {\n      throw new IllegalArgumentException(\n          \"Pubsub object name is longer than 255 characters: \" + name);\n    }\n\n    if (name.startsWith(\"goog\")) {\n      throw new IllegalArgumentException(\"Pubsub object name cannot start with goog: \" + name);\n    }\n","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/PubsubIO.java#L215-L251","documentation":"PubsubIO.validateProjectName checks the project portion of a Pub/Sub subscription/project path against PROJECT_ID_REGEXP. If the supplied project string does not match the expected Google project-id format, an IllegalArgumentException is thrown before any API call is made.","triggerScenarios":"Constructing a Pub/Sub source/sink (PubsubIO.read/write, subscription or topic path parsing) where the project id fails PROJECT_ID_REGEXP.matches — e.g. empty, contains illegal characters, or is a full URL instead of a project id.","commonSituations":"Passing a project number, organization name, or full resource URL where a project id is expected; typos or trailing slashes in the path; env-config driven values like ${PROJECT_ID} left unsubstituted.","solutions":["Supply a valid project id (6-30 lowercase letters, digits, hyphens; must start with a letter)","Interpolate/resolve environment variables before building the path","Strip protocol/host and extra path segments, passing only the project id","Validate the project id with the same regex before passing it into PubsubIO"],"exampleFix":"// before\nString project = \"https://console.cloud.google.com/home/dashboard?project=my-proj\";\n// after\nString project = \"my-proj\"; // matches [a-z][-a-z0-9.:.]{5,29} style project-id regex","handlingStrategy":"validation","validationCode":"private static final Pattern PROJECT_ID = Pattern.compile(\"[a-z][-a-z0-9.:.]{4,28}[-a-z0-9]\");\nif (!PROJECT_ID.matcher(project).matches()) {\n  throw new IllegalArgumentException(\"Invalid project id: \" + project);\n}","typeGuard":null,"tryCatchPattern":"try { PubsubIO.readStrings().fromSubscription(path); } catch (IllegalArgumentException e) { log.error(\"Bad project name: {}\", e.getMessage()); }","preventionTips":["Pass only the bare project id, never a URL or project number","Resolve env/config placeholders before building the path","Centralize resource-path construction with validation","Lint pipeline configs for malformed project ids"],"tags":["java","pubsub","project-id","validation","naming"],"backgroundTag":"invalid-identifier-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-15T02:17:10.978Z"}