aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉamonn McManus <emcmanus@google.com>2024-05-09 09:25:30 -0700
committerCopybara-Service <copybara-worker@google.com>2024-05-09 09:30:45 -0700
commit510c1434ed16dadeeb64a3b841c9ada96e273573 (patch)
tree18f226e64898a9dee04c45434e8ed7dab655d661
parentdbc2baf5bdba18854fe2dacd63fcfe519c169b9b (diff)
downloadprotobuf-510c1434ed16dadeeb64a3b841c9ada96e273573.tar.gz
Add `null` to the list of reserved words.
The previous change claimed to do this in addition to `true` and `false`, but it was not actually in the code. To reiterate the text from the earlier change, now actually reflected entirely in the code: > The identifiers `true`, `false`, and `null` are effectively reserved words in Java, although for some reason they are listed separately from the "keywords" in the Java Language Specification. > > This doesn't matter for regular fields, because a proto field called `true` will be accessed with `getTrue` and `setTrue`. But for extensions, the generated Java code will have a public static field whose name is the same as the name of the extension field, with `_` appended if the name is a reserved word. Previously there was no `_` for `true` etc, so the generated code would not compile. This change should not affect any existing client code in Java. If someone had tried to use an extension called `true` (etc), they would have found that the generated proto code did not compile. Now it is possible to reference such an extension as `true_`. PiperOrigin-RevId: 632174190
-rw-r--r--src/google/protobuf/compiler/java/names.cc22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/google/protobuf/compiler/java/names.cc b/src/google/protobuf/compiler/java/names.cc
index 7f026ecaf..6df146353 100644
--- a/src/google/protobuf/compiler/java/names.cc
+++ b/src/google/protobuf/compiler/java/names.cc
@@ -39,17 +39,17 @@ const char* DefaultPackage(Options options) {
bool IsReservedName(absl::string_view name) {
static const auto& kReservedNames =
*new absl::flat_hash_set<absl::string_view>({
- "abstract", "assert", "boolean", "break", "byte",
- "case", "catch", "char", "class", "const",
- "continue", "default", "do", "double", "else",
- "enum", "extends", "false", "final", "finally",
- "float", "for", "goto", "if", "implements",
- "import", "instanceof", "int", "interface", "long",
- "native", "new", "package", "private", "protected",
- "public", "return", "short", "static", "strictfp",
- "super", "switch", "synchronized", "this", "throw",
- "throws", "transient", "true", "try", "void",
- "volatile", "while",
+ "abstract", "assert", "boolean", "break", "byte",
+ "case", "catch", "char", "class", "const",
+ "continue", "default", "do", "double", "else",
+ "enum", "extends", "false", "final", "finally",
+ "float", "for", "goto", "if", "implements",
+ "import", "instanceof", "int", "interface", "long",
+ "native", "new", "null", "package", "private",
+ "protected", "public", "return", "short", "static",
+ "strictfp", "super", "switch", "synchronized", "this",
+ "throw", "throws", "transient", "true", "try",
+ "void", "volatile", "while",
});
return kReservedNames.contains(name);
}