Commit graph

1456 commits

Author SHA1 Message Date
Protobuf Team Bot
c404f03771 Move the location of linkage_monitor jar from Cloud Storage to Github releases.
PiperOrigin-RevId: 853440778
2026-01-07 15:43:18 -08:00
Protobuf Team Bot
6d5780ff3d Allow writing string to the end of internal buffer instead of enforcing spaceLeft().
PiperOrigin-RevId: 853279267
2026-01-07 08:49:27 -08:00
Mikita Belahlazau
4f076d951f Add metadata annotations for generated Python protobuf symbols.
The pyi generator now includes Kythe annotations for:
*   Extension field constants (e.g., `EXTENSION_FIELD`).
*   Field number constants (e.g., `STRING_FIELD_FIELD_NUMBER`).
*   `Create` methods in generated Stubby client classes.

These annotations allow the Python indexer to link these generated symbols back to their definitions in the `.proto` files.

PiperOrigin-RevId: 852971617
2026-01-06 16:05:56 -08:00
Protobuf Team Bot
9eb9b36e8a Check if ByteString is empty by using isEmpty() instead of == ByteString.EMPTY
PiperOrigin-RevId: 852852532
2026-01-06 11:02:46 -08:00
Protobuf Team Bot
ae67a4c195 Internal version update.
PiperOrigin-RevId: 852733884
2026-01-06 05:27:44 -08:00
Protobuf Team Bot
3657ce3ba3 Allow unused return on various Protobuf methods.
This is only adding the annotation on cases that match standard idioms that return values can be ignored: like collections add/addAll/remove and Builders returning `this`

PiperOrigin-RevId: 852435246
2026-01-05 13:38:10 -08:00
Protobuf Team Bot
7400557a7d Try to avoid concat two bytes right away if two LazyFields contain different extension registries.
PiperOrigin-RevId: 852334989
2026-01-05 09:37:10 -08:00
Sandy Zhang
7beda33399 Clean up dead dist_files targets.
PiperOrigin-RevId: 851412528
2026-01-02 12:19:11 -08:00
Kurt Alfred Kluever
443fef90a1 Mention the UTF-8 variants in the deprecation text of ByteString APIs.
PiperOrigin-RevId: 851339566
2026-01-02 07:44:04 -08:00
Protobuf Team Bot
33b16e8302 Correctly apply JSON recursion limit when parsing an Any-of-Any.
Without this check, an any-of-any-of-any-of-... wouldn't apply the recursion check as intended and cound be arbitrarily deep.

Fixes https://github.com/protocolbuffers/protobuf/issues/25071

PiperOrigin-RevId: 850485466
2025-12-30 12:41:45 -08:00
Kurt Alfred Kluever
c5a346995b Deprecate ByteString.copyFrom(String, String) and ByteString.toString(String); prefer the Charset-accepting APIs instead.
PiperOrigin-RevId: 850392112
2025-12-30 06:25:26 -08:00
Rachel Goldfinger
0404e66d8b Add conformance test for edition unstable
PiperOrigin-RevId: 850054867
2025-12-29 07:41:37 -08:00
Protobuf Team Bot
92f39e0aec Fix unnecessary required field checking on serialize of message-typed map fields.
On map fields the Serialize and SerializedLength create temporary instances of synthetic map entries and .build() on them: this change switches it to instead use buildPartial() in these cases.

This is a semantics observable change in a corner case, but in a bugfix direction: JavaProto's normal semantics is to only check required fields at .build() time, which allows for buildPartial() and then serialize if you want to intentionally serialize with required fields missing or as a microoptimization skip checking for required fields being set.

Only in the case of message-typed-values of map fields serialize may fail with missing required fields: it will happen if the user does buildPartial(), sets it on a map, and then serializes, since the build() on the synthetic map entry will recheck for required fields. After this change the behavior on that shape of flow is consistent with our standard serialize.

PiperOrigin-RevId: 849485221
2025-12-27 08:34:17 -08:00
Protobuf Team Bot
dd7c6f852f Merge AbstractBufferedEncoder base class into its only subclass OutputStreamEncoder.
After the prior cleanup, this is the last use of the base class left and we are unlikely to reuse the base class for another different type, so we can merge it in.

PiperOrigin-RevId: 848198069
2025-12-23 09:08:03 -08:00
Protobuf Team Bot
e51dd08ae9 Delete ByteOutputEncoder as dead code.
PiperOrigin-RevId: 847812962
2025-12-22 10:39:11 -08:00
Protobuf Team Bot
c224a3606f Use Locale.ROOT for all of our formatted error messages.
PiperOrigin-RevId: 846398642
2025-12-18 13:45:47 -08:00
Sandy Zhang
b3e0fc4e1f internal change
PiperOrigin-RevId: 845918159
2025-12-17 14:33:28 -08:00
Protobuf Team Bot
9cca3c189b Make more operations return the ByteString.EMPTY singleton instead of allocating a new byte[0] and a ByteString wrapper around that.
The primary reason to do this is to reduce allocations, but it may give epsilon better runtime characteristics by hitting == paths more often compared to .equals() paths.

Some of the hottest cases of these are actually already handled in layers above, but there's many paths where this is reachable with 0-length strings where we currently will perform an allocation.

PiperOrigin-RevId: 845840649
2025-12-17 11:10:28 -08:00
Protobuf Team Bot
fa68f6b852 Hot path size==0 to return ""
Today when we let it ride it ends up allocating a new String() each timu which is equals but != the "" interned value.

By adding the trivial check up front we can avoid an arbitrary number of separate java.lang.String objects being created.

PiperOrigin-RevId: 845499246
2025-12-16 17:34:15 -08:00
Protobuf Team Bot
531c644c7d Avoid potential exceptions on serialize in the face of malformed lazy extensions.
The behavior before this change was that when a corrupted lazy extension was seen, the first time parse is reached it actually discarded and 0-length byte is stored.

This can led to exceptions in a case of
- Parse some parent message with a messageset with an extension that has malformed bytes
- Call getSerializedLength() on parent, which will see the lazy fields byte length and cache it
- Call .get() on the bad extension, which sees the corruption, this resets only the inner cached size to -1 not any parents
- Serialize the message, serialized length doesn't match the cached serialized length which will throw that the wrong number of bytes were written.

After this change, we instead round-trip the original bytes in the face of corrupted data. This is consistent with cases like wrong-tag cases where we stuff the data into unknown fields instead and don't discard it.

PiperOrigin-RevId: 844814654
2025-12-15 09:58:42 -08:00
Protobuf Team Bot
4c2f2727bc Automated Code Change
PiperOrigin-RevId: 844736039
2025-12-15 06:03:24 -08:00
Protobuf Team Bot
831bb2cb7f Corrected Javadoc for compute*SizeNoTag methods
PiperOrigin-RevId: 843394943
2025-12-11 15:20:27 -08:00
Protobuf Team Bot
1041d6274f Remove unused canUseUnsafe() protected method from GeneratedMessage
This was briefly used by generated code internally as part of the experimental parser/runtime work. This method was never used by protoc generated code otherwise.

We don't consider removal of protected methods for the gencode base classes to be a breaking change if they were never called by any released generated code, as it would only break someone who subclassed GeneratedMessage by hand and wrote code who called this which is not supported. In this case there's essentially no reason for someone to have been interested in calling this anyway.

PiperOrigin-RevId: 843318803
2025-12-11 12:02:45 -08:00
Protobuf Team Bot
7d9733e05f Fix LazyFieldLite.merge to ensure that it always follows this.mergeFrom(other) rather than sometimes other.mergeFrom(this) which unsafely assumes that these two operations are equivalent.
PiperOrigin-RevId: 842809357
2025-12-10 11:36:58 -08:00
Kurt Alfred Kluever
4cfa68115a Automated Code Change
PiperOrigin-RevId: 840238785
2025-12-04 07:53:47 -08:00
Patrice Arruda
f66ad439e1 refactor(protobuf): remove redundant typecast in Timestamps.normalizedTimestamp (#24671)
Removed unnecessary typecast in the normalizedTimestamp method.

Modified: java/util/src/main/java/com/google/protobuf/util/Timestamps.java

Closes #24671

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/24671 from patricearruda84:remove_redundant_check 6491986c2f
PiperOrigin-RevId: 839898550
2025-12-03 13:47:35 -08:00
Protobuf Team Bot
586f74cd20 Small cleanup of Utf8.java
This is no change in functionality, only refactoring names and slightly adjusting control flow for fallback paths.

PiperOrigin-RevId: 839780757
2025-12-03 09:08:08 -08:00
Protobuf Team Bot
35149013bf Add check if sun.misc.Unsafe is present but throws on use, to use the preexisting no-Unsafe paths if it does.
JavaProto is already robust in the absence of sun.misc.Unsafe, and checks for its existence via reflection to use as a performance optimization.

As part of the planned removal of sun.misc.Unsafe, a future JDK will have Unsafe available but most of the methods will throw by default, which would break JavaProto. This creates an odd situation that if it was removed we wouldn't break, but the intermediate turndown state does break us. By adding a usage of one method to see if it throws an UnsupportedOperationException, we avoid breaking users if they use Protobuf in this intermediate turndown state of the API (which will become the default state in a future JDK release).

It is still TBD whether a future release of Protobuf may stop using sun.misc.Unsafe always, or if we may keep this code alive for users running old JDKs; that detail is still TBD depending on performance implications.

https://github.com/protocolbuffers/protobuf/issues/20760

PiperOrigin-RevId: 836715451
2025-11-25 10:08:37 -08:00
Protobuf Team Bot
d95775186d Remove the now-vestigial partial Utf8 complexity.
In the past, as part of supporting Ropes, our Utf8 path had to support verifying if some byte[] were individually invalid Utf8 but actually were valid Utf8 once concatenated, which required the validation library to have complex handling for propagating and checking with partial state.

In a prior change Ropes were simplified to no longer need that behavior and the 'partial' behavior became vestigial internal detail of the Utf8 library. This change is an internal no-op cleanup.

There are potentially more followup cleanup opportunities, this change is oriented towards doing nearly the minimum to replace the int return values with bools, and dropping `int state` input (which is at head always passed as state=COMPLETE). This involved inlining some methods.

PiperOrigin-RevId: 836703657
2025-11-25 09:47:44 -08:00
Protobuf Team Bot
7eef275fa4 Remove UnsafeDirectNioEncoder.
Rename SafeDirectNioEncoder to DirectNioEncoder now that there is no unsafe one.

This encoding path is rarely used (only used on direct Nio buffers, not heap ones). sun.misc.Unsafe is slated for removal, and a quick check of benchmarks shows that the safe version is actually only very slightly slower today, so we will just remove the unsafe path here.

https://github.com/protocolbuffers/protobuf/issues/20760

PiperOrigin-RevId: 833892566
2025-11-18 11:24:54 -08:00
Protobuf Team Bot
2485989764 Internal change.
PiperOrigin-RevId: 832403945
2025-11-14 11:59:31 -08:00
Protobuf Team Bot
acb18a27b0 Correctly handle inputs that consist only of empty buffers
Related to
https://github.com/protocolbuffers/protobuf/issues/17850

PiperOrigin-RevId: 831540481
2025-11-12 14:28:48 -08:00
Protobuf Team Bot
c27a6f3a34 Internal change
PiperOrigin-RevId: 831474664
2025-11-12 11:43:35 -08:00
Liam Miller-Cushon
77c47e9550 Automated Code Change
PiperOrigin-RevId: 830466970
2025-11-10 09:04:31 -08:00
Protobuf Team Bot
3159b1b84f Change RopeByteString's Utf8 validity behavior to avoid needing to have our Utf8 validation library handle validation in the face of straddling surrogate sequences (where it has to handle cases where a given byte sequence is invalid UTF8 but _could_ be valid when concatenated with another byte sequence).
PiperOrigin-RevId: 829490247
2025-11-07 10:31:34 -08:00
Protobuf Team Bot
ddc86abba4 Roll-forward turn down UnsafeDirectNioDecoder and IterableDirectByteBufferDecoder.
PiperOrigin-RevId: 829469943
2025-11-07 09:35:48 -08:00
Protobuf Team Bot
120a94ce17 Remove NioByteString which is empirically never used.
This type was only used with non-array backed ByteBuffers, which in practice does not happen. Any fringe usages which may be invisible to our tracing (including any usages in open source) will not break with this change, which is done at the expense of a copy of the bytes on the way in.

PiperOrigin-RevId: 829088261
2025-11-06 13:41:35 -08:00
Protobuf Team Bot
ccc6c45f65 Fix warnings about object for varargs usage in tests.
PiperOrigin-RevId: 829078809
2025-11-06 13:16:45 -08:00
Protobuf Team Bot
4cc981c7f8 Automated rollback of commit 2224cbb5ae.
PiperOrigin-RevId: 829027233
2025-11-06 11:07:48 -08:00
Protobuf Team Bot
2224cbb5ae Turn down UnsafeDirectNioDecoder and IterableDirectByteBufferDecoder.
PiperOrigin-RevId: 828983506
2025-11-06 09:24:40 -08:00
Protobuf Team Bot
195da42b90 Automated Code Change
PiperOrigin-RevId: 828916640
2025-11-06 05:52:47 -08:00
Protobuf Team Bot
2e6183348e Remove UnpairedSurrogateException from Protobuf Utf8.
In practice the way we used this was:
- The UTF8 util refused to handle strings with dangling UTF16 surrogates

- The CodedOutputStream above always would have to catch the exception and fall back to the 'naive' implementation.

Broadly we're moving serverside things onto the 'naive implementation' which does replacement characters inside the Utf8 utility anyway, which makes those paths never throw this exception. So instead reshape this so the Utf8 utility does replacement character behavior, and the layer above gets that behavior already

This is nearly entirely a behavior no-op: the main thing is losing a log-warning in one path that warns that the unpaired surrogate situation was happening.

Note that replacement characters on encode of malformed Utf16 is just a pretty safe behavior: it can never occur when parsing wire format, instead it can only happen from someone doing something odd with their Java application code and there's realistically no real signal in the data being lost. That contrasts with malformed Utf8 from the wire at parse, where someone may realistically have encoding type confusion and a parse>serialize round trip silently leading to replacement characters is potentially dangerous for data loss.

PiperOrigin-RevId: 828473999
2025-11-05 08:15:39 -08:00
Protobuf Team Bot
fa7535d895 Correctly size the map/list from the builder to avoid re-allocation or over-allocation.
PiperOrigin-RevId: 828241054
2025-11-04 19:28:04 -08:00
Protobuf Team Bot
57770eb7b7 Remove defunct protected mergeFromAndMakeImmutableInternal method. This method was planned to be used by gencode but was never used in practice.
As a protected method never actually called by any gencode, removal is not considered a breaking change.

PiperOrigin-RevId: 827551358
2025-11-03 10:20:55 -08:00
Protobuf Team Bot
924aa0642f Internal
PiperOrigin-RevId: 826526179
2025-10-31 09:54:51 -07:00
Protobuf Team Bot
ec86098c76 Change UnsafeProcessor.encodeUtf8(ByteBuffer out) to use the 'naive' strategy that we already used for the (byte[] out) case as a performance improvement.
PiperOrigin-RevId: 826012827
2025-10-30 07:03:21 -07:00
Protobuf Team Bot
0ad8c2a338 Automated Code Change
PiperOrigin-RevId: 825843518
2025-10-29 21:13:04 -07:00
Mike Kruskal
90de3d1a94 Add edition 2024 support to kotlin native.
The only thing missing was handling of java_multiple_files, which can reuse our java helpers.

PiperOrigin-RevId: 825813542
2025-10-29 19:40:12 -07:00
Protobuf Team Bot
b5b9f2c0ba Internal change.
PiperOrigin-RevId: 825177275
2025-10-28 13:30:55 -07:00
Angie Lin
1270e456f4 Fix quote escaping in JsonFormat.print() for FieldMasks.
https://github.com/protocolbuffers/protobuf/issues/24083

PiperOrigin-RevId: 824592626
2025-10-27 11:06:28 -07:00