Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Add support for Spring Boot 4 and Spring 7 ([#4601](https://github.com/getsentry/sentry-java/pull/4601))
- NOTE: Our `sentry-opentelemetry-agentless-spring` is not working yet for Spring Boot 4. Please use `sentry-opentelemetry-agent` until OpenTelemetry has support for Spring Boot 4.
- Replace `UUIDGenerator` implementation with Apache licensed code ([#4662](https://github.com/getsentry/sentry-java/pull/4662))

## 8.20.0

Expand Down
74 changes: 36 additions & 38 deletions sentry/src/main/java/io/sentry/util/UUIDGenerator.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* Adapted from: http://github.com/baomidou/dynamic-datasource/blob/bae2677b83abad549e3ddf41b286749515360e7b/dynamic-datasource-spring/src/main/java/com/baomidou/dynamic/datasource/tx/LocalTxUtil.java
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* Copyright © 2018 organization baomidou
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
* http://www.apache.org/licenses/LICENSE-2.0
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.sentry.util;
Expand All @@ -35,36 +28,41 @@ public final class UUIDGenerator {

@SuppressWarnings("NarrowingCompoundAssignment")
public static long randomHalfLengthUUID() {
Random random = SentryRandom.current();
Random ng = SentryRandom.current();
byte[] randomBytes = new byte[8];
random.nextBytes(randomBytes);
randomBytes[6] &= 0x0f; /* clear version */
randomBytes[6] |= 0x40; /* set to version 4 */

ng.nextBytes(randomBytes);
// clear version
randomBytes[6] &= 0x0f;
// set to version 4
randomBytes[6] |= 0x40;
long msb = 0;

for (int i = 0; i < 8; i++) msb = (msb << 8) | (randomBytes[i] & 0xff);

for (int i = 0; i < 8; i++) {
msb = (msb << 8) | (randomBytes[i] & 0xff);
}
return msb;
}

@SuppressWarnings("NarrowingCompoundAssignment")
public static UUID randomUUID() {
Random random = SentryRandom.current();
Random ng = SentryRandom.current();
byte[] randomBytes = new byte[16];
random.nextBytes(randomBytes);
randomBytes[6] &= 0x0f; /* clear version */
randomBytes[6] |= 0x40; /* set to version 4 */
randomBytes[8] &= 0x3f; /* clear variant */
randomBytes[8] |= (byte) 0x80; /* set to IETF variant */

ng.nextBytes(randomBytes);
// clear version
randomBytes[6] &= 0x0f;
// set to version 4
randomBytes[6] |= 0x40;
// clear variant
randomBytes[8] &= 0x3f;
// set to IETF variant
randomBytes[8] |= 0x80;
long msb = 0;
long lsb = 0;

for (int i = 0; i < 8; i++) msb = (msb << 8) | (randomBytes[i] & 0xff);

for (int i = 8; i < 16; i++) lsb = (lsb << 8) | (randomBytes[i] & 0xff);

for (int i = 0; i < 8; i++) {
msb = (msb << 8) | (randomBytes[i] & 0xff);
}
for (int i = 8; i < 16; i++) {
lsb = (lsb << 8) | (randomBytes[i] & 0xff);
}
return new UUID(msb, lsb);
}
}
Loading