{"record":{"id":"95594edcf14fe00b","repo":"grpc/grpc-java","slug":"name-is-absent-or-empty","errorCode":null,"errorMessage":"\"name\" is absent or empty","messagePattern":"\"name\" is absent or empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"authz/src/main/java/io/grpc/authz/AuthorizationPolicyTranslator.java","lineNumber":177,"sourceCode":"   * Translates a gRPC authorization policy in JSON string to Envoy RBAC policies.\n   * On success, will return one of the following -\n   * 1. One allow RBAC policy or,\n   * 2. Two RBAC policies, deny policy followed by allow policy.\n   * If the policy cannot be parsed or is invalid, an exception will be thrown.\n   */\n  public static List<RBAC> translate(String authorizationPolicy) \n            throws IllegalArgumentException, IOException {\n    Object jsonObject = JsonParser.parse(authorizationPolicy);\n    if (!(jsonObject instanceof Map)) {\n      throw new IllegalArgumentException(\n          \"Authorization policy should be a JSON object. Found: \"\n          + (jsonObject == null ? null : jsonObject.getClass()));\n    }\n    @SuppressWarnings(\"unchecked\")\n    Map<String, ?> json = (Map<String, ?>)jsonObject;\n    String name = JsonUtil.getString(json, \"name\");\n    if (name == null || name.isEmpty()) {\n      throw new IllegalArgumentException(\"\\\"name\\\" is absent or empty\");\n    }\n    List<RBAC> rbacs = new ArrayList<>();\n    List<Map<String, ?>> objects = JsonUtil.getListOfObjects(json, \"deny_rules\");\n    if (objects != null && !objects.isEmpty()) {\n      rbacs.add(\n          RBAC.newBuilder()\n          .setAction(Action.DENY)\n          .putAllPolicies(parseRules(objects, name))\n          .build());\n    }\n    objects = JsonUtil.getListOfObjects(json, \"allow_rules\");\n    if (objects == null || objects.isEmpty()) {\n      throw new IllegalArgumentException(\"\\\"allow_rules\\\" is absent\");\n    }\n    rbacs.add(\n        RBAC.newBuilder()\n        .setAction(Action.ALLOW)\n        .putAllPolicies(parseRules(objects, name))","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/grpc/grpc-java/blob/64daddc1f3d1975670f769f3e97bde8b2ba32d25/authz/src/main/java/io/grpc/authz/AuthorizationPolicyTranslator.java#L159-L195","documentation":"A valid gRPC authorization policy must carry a non-empty top-level \"name\" field identifying the policy. After confirming the input is a JSON object, translate() reads JsonUtil.getString(json, \"name\") and throws IllegalArgumentException when it is missing, null, or an empty string.","triggerScenarios":"Calling AuthorizationPolicyTranslator.translate(policyJson) where the JSON object has no \"name\" key, or \"name\": null, or \"name\": \"\".","commonSituations":"Hand-written policy files omitting the required name field, policies copied from examples that strip metadata, programmatic JSON built without setting name.","solutions":["Add a non-empty \"name\" string field at the top level of the authorization policy JSON","Validate required fields (name, rules) before calling translate()","If generating the policy in code, always set the name field"],"exampleFix":"// before\n{\"deny_rules\": [{\"matches\": [...], \"requires\": {...}}]}\n// after\n{\"name\": \"my-authz-policy\", \"deny_rules\": [{\"matches\": [...], \"requires\": {...}}]}","handlingStrategy":"validation","validationCode":"JsonObject o = JsonParser.parseString(policyJson).getAsJsonObject();\nif (!o.has(\"name\") || o.get(\"name\").isJsonNull() || o.get(\"name\").getAsString().isEmpty()) {\n  throw new IllegalArgumentException(\"policy requires non-empty 'name'\");\n}","typeGuard":"static boolean hasNonEmptyName(Map<String, ?> json) {\n  Object n = json.get(\"name\");\n  return n instanceof String && !((String) n).isEmpty();\n}","tryCatchPattern":"try {\n  List<RBAC> rbacs = AuthorizationPolicyTranslator.translate(policyJson);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"name\")) { /* fix policy file */ }\n  throw e;\n}","preventionTips":["Always include a \"name\" field when authoring policies","Validate the policy JSON against the authz schema in CI","Use schema-checked templates for policy generation"],"tags":["grpc","authz","validation","json"],"backgroundTag":"missing-required-config-field","analyzedSha":"64daddc1f3d1975670f769f3e97bde8b2ba32d25","analyzedAt":"2026-09-08T06:14:57.704Z","contentChangedAt":"2026-09-08T06:14:57.704Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}