Commit graph

1623 commits

Author SHA1 Message Date
Protobuf Team Bot
fb35e82c10 Updating version.json and repo version numbers to: 36.1-dev 2026-08-20 02:32:57 -07:00
Protobuf Team Bot
3f17acbf7f Updating version.json and repo version numbers to: 36.0 2026-08-20 02:32:56 -07:00
Jason Aragorn Tobias Lunn
15e93345f8 Add json_options.proto and json_enumvalue_options.proto and/or gencode derived from them to release artifacts
* `protoc`: Included in zips alongside binary
* Java: Generated classes have been added to the Maven `util` artifact
* Ruby: Generated classes have been added to gems
* CMake: `.proto` files are included in installation

PiperOrigin-RevId: 957382561
(cherry picked from commit 713b6a4a24)
2026-08-03 11:52:16 -04:00
Tony Liao
5945409fcc (Second try) Cache the custom JSON names of enum fields upon first lookup.
Benchmark                                                     Mode  Cnt    Score   Error  Units
JsonFormatBenchmark.benchmarkParseJsonCustom                  avgt   50    3.974 ± 0.037  us/op
JsonFormatBenchmark.benchmarkParseJsonDefault                 avgt   50    3.837 ± 0.114  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknown                 avgt   50   33.699 ± 0.256  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknownIgnored          avgt   50   26.216 ± 0.167  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonCustom          avgt   50   20.698 ± 0.457  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonDefault         avgt   50   12.277 ± 0.112  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonUnknownIgnored  avgt   50  364.327 ± 5.504  us/op

Benchmark                                                     Mode  Cnt    Score   Error  Units
JsonFormatBenchmark.benchmarkParseJsonCustom                  avgt   50    5.049 ± 0.057  us/op
JsonFormatBenchmark.benchmarkParseJsonDefault                 avgt   50    3.879 ± 0.072  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknown                 avgt   50   33.157 ± 0.378  us/op
JsonFormatBenchmark.benchmarkParseJsonUnknownIgnored          avgt   50   26.461 ± 0.151  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonCustom          avgt   50   14.664 ± 0.085  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonDefault         avgt   50   12.230 ± 0.101  us/op
JsonFormatBenchmark.benchmarkParseRepeatedJsonUnknownIgnored  avgt   50  350.246 ± 5.642  us/op

PiperOrigin-RevId: 949670944
2026-07-21 15:07:25 -04:00
Tony Liao
73d654316c Automated rollback of commit 7db08e8f1b.
PiperOrigin-RevId: 949606118
2026-07-21 15:07:15 -04:00
Tony Liao
bcaa1e5f14 Automated rollback of commit 7a39a4e313.
PiperOrigin-RevId: 947163030
2026-07-21 15:07:06 -04:00
Tony Liao
bff6ed1325 json/java: add json_name enumval support
PiperOrigin-RevId: 945901714
2026-07-21 15:06:46 -04:00
Protobuf Team Bot
f857b754a8 Updating version.json and repo version numbers to: 36.0-dev 2026-07-09 12:57:03 -07:00
Protobuf Team Bot
c852f4fa61 Updating version.json and repo version numbers to: 36.0-rc1 2026-07-09 12:57:02 -07:00
Protobuf Team Bot
706fc1e3cb Optimize SmallSortedMap to improve getAllFields() efficiency.
PiperOrigin-RevId: 944593820
2026-07-08 11:08:58 -07:00
Mark Hansen
5759717273 Automated rollback of commit 42b411e7c9.
PiperOrigin-RevId: 944198382
2026-07-07 18:19:12 -07:00
Protobuf Team Bot
42b411e7c9 Optimize Java Lite Parser Registry with Centralized Cache
Avoid generating double-checked locking inside every generated message class's
dynamicMethod(GET_PARSER) by centralizing the parser instantiation and caching
in a thread-safe map inside GeneratedMessageLite.

This saves substantial DEX and ODEX size for apps with many protobuf classes.

Note: This change requires the generated code to run against a runtime of at
least the same version. Mixing new generated code with an older runtime version
is not supported (see https://protobuf.dev/support/cross-version-runtime-guarantee/).
PiperOrigin-RevId: 944139195
2026-07-07 15:57:19 -07:00
Rachel Goldfinger
d5e039a302 Make Timestamps.parse() attempt non-lenient parsing first and warning if this fails.
PiperOrigin-RevId: 944126931
2026-07-07 15:34:12 -07:00
Protobuf Team Bot
5e24bccb66 Auto-generate files after cl/944116273 2026-07-07 22:24:32 +00:00
Jason Aragorn Tobias Lunn
636ae747e6 Update our compiled_edition_default's maximum_edition to 2026
PiperOrigin-RevId: 944116273
2026-07-07 15:13:49 -07:00
Rachel Goldfinger
ab69831380 Add a warning for potential OneofDescriptor collisions prior to Q1 2027 breaking changes.
PiperOrigin-RevId: 943277587
2026-07-06 07:37:05 -07:00
Protobuf Team Bot
e1b94ce8f9 Optimize MapEntry allocations during map serialization
PiperOrigin-RevId: 941708409
2026-07-02 08:16:13 -07:00
Tobias Werth
3907d14b7d Automated Code Change
PiperOrigin-RevId: 941537305
2026-07-02 01:08:39 -07:00
Protobuf Team Bot
06076f5c2c Check MessageLite.class.isAssignableFrom() always, not just in the fallback path.
PiperOrigin-RevId: 941284190
2026-07-01 14:07:32 -07:00
Liam Miller-Cushon
6fc9d438b7 Remove 'The descriptor for type ... cannot be found and a placeholder is created for it' logs
PiperOrigin-RevId: 939963336
2026-06-29 12:17:15 -07:00
Protobuf Team Bot
50d0d1bf0f Document that DiscardUnknownFieldsParser does not discard unrecognized closed enum values.
Fixes https://github.com/protocolbuffers/protobuf/issues/23019

PiperOrigin-RevId: 938127796
2026-06-25 12:27:07 -07:00
Tristan
c56cd5b441 Reject negative size in mergeDelimitedFrom (#28097)
## Summary

`mergeDelimitedFrom` passes the return value of `readRawVarint32` directly to `LimitedInputStream` without checking for negative values. For 5-byte varints encoding values >= 2^31, `readRawVarint32` returns a negative int (e.g., `\x80\x80\x80\x80\x08` decodes to -2147483648).

`LimitedInputStream` with a negative limit immediately returns EOF (`if (limit <= 0) return -1`), causing the parser to produce a default/empty message and return `true` (success). The actual message body bytes remain unconsumed in the stream, permanently desynchronizing subsequent `parseDelimitedFrom` calls.

## Fix

Add `if (size < 0) throw InvalidProtocolBufferException.negativeSize()` before constructing `LimitedInputStream`.

## Test plan

- [x] Verified with PoC: 5-byte varint prefix encoding 2^31 previously produced empty message + stream desync; after fix, `negativeSize` exception thrown
- [ ] Existing unit tests pass

Closes #28097

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/28097 from TristanInSec:fix/merge-delimited-negative-size 7ccb18676e
PiperOrigin-RevId: 937547094
2026-06-24 14:07:37 -07:00
Protobuf Team Bot
6aacd4ddc1 Improve the behavior of StreamDecoder in the face of large ints on the wire.
PiperOrigin-RevId: 937496635
2026-06-24 12:36:50 -07:00
Protobuf Team Bot
3245bdb028 Small optimizations to Java JsonFormat.
- Apply a fast path to Uint64 parse where we try to parse it directly before falling back to the BigDecimal path. This optimization is preexisting on int64 and int32 and uint32 but was missed on Uint64

- Avoid doing out.append(value.subSequence(start, end)) which forces an intermediate copy the string, instead use the out.append(value, start, end)

PiperOrigin-RevId: 937290790
2026-06-24 06:14:18 -07:00
Liam Miller-Cushon
974e76e820 Replace getClass() null checks with Objects.requireNonNull in java lite gencode
PiperOrigin-RevId: 934860264
2026-06-19 04:37:16 -07:00
Liam Miller-Cushon
31ef11cb59 Update Java protobuf generator to use Objects.requireNonNull
PiperOrigin-RevId: 934288237
2026-06-18 05:25:52 -07:00
petedmarsh
16b949d98a Json format lienent tests (#27622)
Because JsonFormat uses GSON to parse JSON it has a variety of
leniencies, e.g. allowing keys and values to skip quotes:

```
{hello: world}
```

These behaviours are not part of the ProtoJSON format but they are
behaviours that JsonFormat's parser has. It's possible someone in the
wild depends upon these unknowingly. This adds explicit tests for these
behaviours to make sure that they are not accidentally lost in future.

Closes #27622

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/27622 from petedmarsh:json-format-lienent-tests edebd543cd
PiperOrigin-RevId: 933849754
2026-06-17 12:03:07 -07:00
Protobuf Team Bot
1d1c1b9f61 Remove unused nextCalledBeforeRemove from SmallSortedMap, as the code path does not exist in the internal implementation, and only immutable maps will be exposed to users.
PiperOrigin-RevId: 932635956
2026-06-15 13:29:47 -07:00
Protobuf Team Bot
ea0e67a9ca Restore the prior behavior of gencode catches for now; while it did drink the gencode it caused a regression in some JIT behavior.
No releases were cut with this change so it is safe to remove.

PiperOrigin-RevId: 932423133
2026-06-15 06:29:39 -07:00
Protobuf Team Bot
261f4cabf1 Optimize ArrayDecoder limit handling (again)
PiperOrigin-RevId: 932410076
2026-06-15 06:03:07 -07:00
Protobuf Team Bot
6beea4e08a Remove unused Fieldset descendingIterator, which saves us some allocations
PiperOrigin-RevId: 931358824
2026-06-12 15:20:28 -07:00
Protobuf Team Bot
7ab792b969 Add link to the page which explains that deterministic != canonical on our apis which let you set determinsitic serialization
PiperOrigin-RevId: 930485402
2026-06-11 06:20:08 -07:00
Protobuf Team Bot
5f91a74c50 Fix edge case on recursion limit for groups in a Lite parse path.
Note that as this case is only reachable for known groups, its not a usable primitive for fully unconstrained recursion, since even if a recursive schema did use a group it would call back to a message between, meaning that even in such an obscure case this would only unlock reaching depth 200 not unconstrained.

PiperOrigin-RevId: 930082333
2026-06-10 14:36:34 -07:00
Protobuf Team Bot
acb6c197da Remove defunct Reader and Writer interfaces from JavaProto
These interfaces were part of the experimental runtime, and before this change have exactly one concrete implementation each. This CL simply deletes the interfaces and inlines the corresponding concrete type wherever they were named.

PiperOrigin-RevId: 930019405
2026-06-10 12:48:25 -07:00
Protobuf Team Bot
7caffc11ee Partial rollforward of cl/928600418: merge HeapNioEncoder into ArrayEncoder.
The previous change looked to get down to exactly 2 CodedOutputStream concrete classes: unfortunately some users are relying on the incidental-but-reliable behavior that CodedOutputStreams with ByteBuffers do immediately push the content without a flush() but that the position update does not apply until you call flush(). This oddity has been incidentally/accidentally true for both Heap and Direct ByteBuffer cases even though they didn't use a common codepath.

To move incrementally forward, we can merge in HeapNio into ArrayEncoder without touching DirectNio. For now this still leaves 3  totalconcrete classes, but it will achieve the 'exactly 2 concrete classes loaded' for any server if they never reach DirectNioEncoder or never reach the OutputStreamEncoder.

PiperOrigin-RevId: 929337270
2026-06-09 12:24:57 -07:00
Protobuf Team Bot
964fe23b18 Restrict Protobuf.java methods to GeneratedMessageLite as part of experimental runtime turndown.
This requires sprinkling some casts around locally, mainly surrounding the mismatch of apis that return `MessageLite` which on LiteRuntime is guaranteed to be `GeneratedMessageLite`, but statically thats not known because Full messages also implement it.

PiperOrigin-RevId: 928716180
2026-06-08 12:44:48 -07:00
Protobuf Team Bot
f770097e46 Optimize JsonFormat handling of Struct/Value by casting gencode accessors instead of reflection.
This still retains the reflection path for these types so that it will continue to handle DynamicMessage printing correctly.

PiperOrigin-RevId: 928689274
2026-06-08 11:51:02 -07:00
Protobuf Team Bot
5d01f7bd22 Optimize Java JsonFormat string printing path.
- Use a lookup table for the replacement characters in the ascii range (which is all of the characters that gson escapes except for exactly 2).

- Stream the escapes out ourselves instead of going through gson.toJson(val.toString()) which goes through a lot of heavy gson machinery and makes several copies of the string.

We exactly match the choices that gson made for escapes here to make this an implementation detail change with no observable difference.

PiperOrigin-RevId: 928654085
2026-06-08 10:51:44 -07:00
Protobuf Team Bot
b9e2715850 Automated rollback of commit 2db709e0a0.
PiperOrigin-RevId: 928600418
2026-06-08 09:18:26 -07:00
Protobuf Team Bot
2db709e0a0 Reduce CodedOutputStream concrete subclasses to 2
The purpose of this change is guarantee the JIT can perform always bimorphization is possible in all paths which are handling a CodedOutputStream, which can in turn unlock significant other optimization wins.

PiperOrigin-RevId: 928539681
2026-06-08 07:00:00 -07:00
Protobuf Team Bot
b6c2e87291 Automated Code Change
PiperOrigin-RevId: 928516242
2026-06-08 06:03:39 -07:00
Protobuf Team Bot
07454526e2 Automated Code Change
PiperOrigin-RevId: 928508944
2026-06-08 05:43:33 -07:00
Stefan Haustein
71263ce02d Internal change
PiperOrigin-RevId: 928436147
2026-06-08 02:40:47 -07:00
Protobuf Team Bot
0d1d7734eb Rename SafeProcessor/UnsafeProcessor to MobileProcessor/ServerProcessor in Utf8.java
It used to be that the UnsafeProcessor was named that because it used sun.misc.Unsafe, and SafeProcessor did not.

However, over time as optimizations shifted the dominant difference was actually that UnsafeProcessor was targeting serverside and SafeProcess targeted Android (even though we otherwise heavily use sun.misc.Unsafe on Android).

Since we no longer sun.misc.Unsafe in either path now, its time to change the names.

PiperOrigin-RevId: 927336258
2026-06-05 09:33:47 -07:00
Protobuf Team Bot
45c6cbedda Add @SuppressWarnings("removal") to Lite-only classes that will still use sun.misc.Unsafe for now.
PiperOrigin-RevId: 927301764
2026-06-05 08:03:13 -07:00
Protobuf Team Bot
3de8c73465 Remove dead BinaryReader.java
This was part of the experimental Java runtime, which is now defunct.

PiperOrigin-RevId: 927300718
2026-06-05 07:59:35 -07:00
Protobuf Team Bot
dd543428c7 Automated Code Change
PiperOrigin-RevId: 927243592
2026-06-05 05:44:19 -07:00
Protobuf Team Bot
94de7ab2b3 Introduce getMessageExtensionOrNull for extendable messages to avoid the code pattern of hasExtension() ? getExtension : null which takes an extra extension lookup.
PiperOrigin-RevId: 926787242
2026-06-04 11:17:43 -07:00
Protobuf Team Bot
791fbe2249 Support merging lazy fields with different default instances but equal descriptor types; e.g. DynamicMessage
Lazy field should only be applicable to full message, whose `mergeFrom(Message)` supports merging from a different message but with the same descriptor. Therefore, this change abandons the default instance check in the lazy field impl.

Also note that InternalLazyField currently belongs to the lite runtime, so direct access to descriptors is infeasible, thus depending on the mergeFrom overrides to invoke the full merging method.

PiperOrigin-RevId: 926112976
2026-06-03 10:15:18 -07:00
Protobuf Team Bot
50ac9feec5 Micro-optimize latin1Cat() to speed up protobuf descriptor initialization.
We have to break up the descriptors into multiple strings because of the 64k cap on string literals and then join them back up at runtime. This change we avoid building the intermediate joined string before extracting it back as byte[], and instead pre-allocate the total byte[] array first and turns each 64kb segment to byte[] and uses System.arraycopy to copy them directly.

This avoids some pointless work, but also removes garbage copies. Note that its a garbage copy that should be escape-analysis by the JVM and so should be very cheap, but still cheaper not to.

PiperOrigin-RevId: 925969602
2026-06-03 05:56:44 -07:00