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
2619package 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