Skip to content

Commit 7314dbe

Browse files
authored
Replace UUIDGenerator implementation with Apache licensed code (#4662)
* Replace UUIDGenerator implementation with Apache licensed code * changelog
1 parent a155b36 commit 7314dbe

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Add support for Spring Boot 4 and Spring 7 ([#4601](https://github.com/getsentry/sentry-java/pull/4601))
88
- 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.
9+
- Replace `UUIDGenerator` implementation with Apache licensed code ([#4662](https://github.com/getsentry/sentry-java/pull/4662))
910

1011
## 8.20.0
1112

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

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

3629
@SuppressWarnings("NarrowingCompoundAssignment")
3730
public static long randomHalfLengthUUID() {
38-
Random random = SentryRandom.current();
31+
Random ng = SentryRandom.current();
3932
byte[] randomBytes = new byte[8];
40-
random.nextBytes(randomBytes);
41-
randomBytes[6] &= 0x0f; /* clear version */
42-
randomBytes[6] |= 0x40; /* set to version 4 */
43-
33+
ng.nextBytes(randomBytes);
34+
// clear version
35+
randomBytes[6] &= 0x0f;
36+
// set to version 4
37+
randomBytes[6] |= 0x40;
4438
long msb = 0;
45-
46-
for (int i = 0; i < 8; i++) msb = (msb << 8) | (randomBytes[i] & 0xff);
47-
39+
for (int i = 0; i < 8; i++) {
40+
msb = (msb << 8) | (randomBytes[i] & 0xff);
41+
}
4842
return msb;
4943
}
5044

5145
@SuppressWarnings("NarrowingCompoundAssignment")
5246
public static UUID randomUUID() {
53-
Random random = SentryRandom.current();
47+
Random ng = SentryRandom.current();
5448
byte[] randomBytes = new byte[16];
55-
random.nextBytes(randomBytes);
56-
randomBytes[6] &= 0x0f; /* clear version */
57-
randomBytes[6] |= 0x40; /* set to version 4 */
58-
randomBytes[8] &= 0x3f; /* clear variant */
59-
randomBytes[8] |= (byte) 0x80; /* set to IETF variant */
60-
49+
ng.nextBytes(randomBytes);
50+
// clear version
51+
randomBytes[6] &= 0x0f;
52+
// set to version 4
53+
randomBytes[6] |= 0x40;
54+
// clear variant
55+
randomBytes[8] &= 0x3f;
56+
// set to IETF variant
57+
randomBytes[8] |= 0x80;
6158
long msb = 0;
6259
long lsb = 0;
63-
64-
for (int i = 0; i < 8; i++) msb = (msb << 8) | (randomBytes[i] & 0xff);
65-
66-
for (int i = 8; i < 16; i++) lsb = (lsb << 8) | (randomBytes[i] & 0xff);
67-
60+
for (int i = 0; i < 8; i++) {
61+
msb = (msb << 8) | (randomBytes[i] & 0xff);
62+
}
63+
for (int i = 8; i < 16; i++) {
64+
lsb = (lsb << 8) | (randomBytes[i] & 0xff);
65+
}
6866
return new UUID(msb, lsb);
6967
}
7068
}

0 commit comments

Comments
 (0)