Skip to content

Commit cd34338

Browse files
authored
Merge branch 'main' into access-token-callback
2 parents e6da1ba + 1797e17 commit cd34338

18 files changed

+137
-158
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ dependencies {
130130
implementation 'org.osgi:org.osgi.core:6.0.0',
131131
'org.osgi:org.osgi.compendium:5.0.0'
132132
compileOnly 'com.azure:azure-security-keyvault-keys:4.2.8',
133-
'com.azure:azure-identity:1.3.3',
133+
'com.azure:azure-identity:1.7.0-beta.2',
134134
'org.antlr:antlr4-runtime:4.9.2',
135135
'com.google.code.gson:gson:2.8.7',
136136
'org.bouncycastle:bcprov-jdk15on:1.69',
@@ -152,7 +152,7 @@ dependencies {
152152
'com.google.code.gson:gson:2.8.7',
153153
'org.bouncycastle:bcprov-jdk15on:1.69',
154154
'com.azure:azure-security-keyvault-keys:4.2.8',
155-
'com.azure:azure-identity:1.3.3',
155+
'com.azure:azure-identity:1.7.0-beta.2',
156156
'com.microsoft.azure:adal4j:1.6.7',
157157
'com.h2database:h2:1.4.200'
158158
}

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363

6464
<!-- Driver Dependencies -->
6565
<org.osgi.core.version>6.0.0</org.osgi.core.version>
66-
<azure-security-keyvault-keys.version>4.4.4</azure-security-keyvault-keys.version>
66+
<azure-security-keyvault-keys.version>4.5.1</azure-security-keyvault-keys.version>
6767
<azure-identity.version>1.7.0-beta.2</azure-identity.version>
68-
<msal.version>1.13.0</msal.version>
68+
<msal.version>1.13.3</msal.version>
6969
<org.osgi.compendium.version>5.0.0</org.osgi.compendium.version>
7070
<antlr-runtime.version>4.9.3</antlr-runtime.version>
7171
<com.google.code.gson.version>2.9.0</com.google.code.gson.version>
@@ -109,7 +109,7 @@
109109
<dependency>
110110
<groupId>com.microsoft.azure</groupId>
111111
<artifactId>msal4j</artifactId>
112-
<version>1.13.0</version>
112+
<version>1.13.3</version>
113113
<optional>true</optional>
114114
</dependency>
115115

src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ enum Result {
24162416

24172417
// list of addresses for ip selection by type preference
24182418
private static ArrayList<InetAddress> addressList = new ArrayList<>();
2419-
private static final Lock ADDRESS_LIST_LOCK = new ReentrantLock();
2419+
private static final Lock addressListLock = new ReentrantLock();
24202420

24212421
/**
24222422
* Constructs a new SocketFinder object with appropriate traceId
@@ -2765,7 +2765,7 @@ private SocketFactory getSocketFactory() throws IOException {
27652765
*/
27662766
private InetSocketAddress getInetAddressByIPPreference(String hostName,
27672767
int portNumber) throws IOException, SQLServerException {
2768-
ADDRESS_LIST_LOCK.lock();
2768+
addressListLock.lock();
27692769
try {
27702770
InetSocketAddress addr = InetSocketAddress.createUnresolved(hostName, portNumber);
27712771
for (int i = 0; i < addressList.size(); i++) {
@@ -2775,7 +2775,7 @@ private InetSocketAddress getInetAddressByIPPreference(String hostName,
27752775
}
27762776
return addr;
27772777
} finally {
2778-
ADDRESS_LIST_LOCK.unlock();
2778+
addressListLock.unlock();
27792779
}
27802780
}
27812781

@@ -2838,7 +2838,7 @@ private Socket getSocketByIPPreference(String hostName, int portNumber, int time
28382838
// Note that Socket(host, port) throws an UnknownHostException if the host name
28392839
// cannot be resolved, but that InetSocketAddress(host, port) does not - it sets
28402840
// the returned InetSocketAddress as unresolved.
2841-
if (addr.isUnresolved()) {
2841+
if (addr != null && addr.isUnresolved()) {
28422842
if (logger.isLoggable(Level.FINER)) {
28432843
logger.finer(this.toString() + "Failed to resolve host name: " + hostName
28442844
+ ". Using IP address from DNS cache.");
@@ -2859,7 +2859,7 @@ private Socket getSocketByIPPreference(String hostName, int portNumber, int time
28592859
* Boolean switch for IPv6 first
28602860
*/
28612861
private void fillAddressList(InetAddress[] addresses, boolean ipv6first) {
2862-
ADDRESS_LIST_LOCK.lock();
2862+
addressListLock.lock();
28632863
try {
28642864
addressList.clear();
28652865
if (ipv6first) {
@@ -2876,7 +2876,7 @@ private void fillAddressList(InetAddress[] addresses, boolean ipv6first) {
28762876
}
28772877
}
28782878
} finally {
2879-
ADDRESS_LIST_LOCK.unlock();
2879+
addressListLock.unlock();
28802880
}
28812881
}
28822882

@@ -4155,7 +4155,7 @@ void writeString(String value) throws SQLServerException {
41554155
int charsCopied = 0;
41564156
int length = value.length();
41574157
while (charsCopied < length) {
4158-
long bytesToCopy = 2 * (length - charsCopied);
4158+
long bytesToCopy = 2 * ((long) length - charsCopied);
41594159

41604160
if (bytesToCopy > valueBytes.length)
41614161
bytesToCopy = valueBytes.length;
@@ -6053,7 +6053,8 @@ private void writeScaledTemporal(GregorianCalendar cal, int subSecondNanos, int
60536053
+ 60 * 60 * cal.get(Calendar.HOUR_OF_DAY);
60546054

60556055
// Scale nanos since midnight to the desired scale, rounding the value as necessary
6056-
long divisor = Nanos.PER_MAX_SCALE_INTERVAL * (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - scale);
6056+
long divisor = Nanos.PER_MAX_SCALE_INTERVAL
6057+
* (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - (double) scale);
60576058

60586059
// The scaledNanos variable represents the fractional seconds of the value at the scale
60596060
// indicated by the scale variable. So, for example, scaledNanos = 3 means 300 nanoseconds
@@ -6195,7 +6196,8 @@ byte[] writeEncryptedScaledTemporal(GregorianCalendar cal, int subSecondNanos, i
61956196
+ 60 * 60 * cal.get(Calendar.HOUR_OF_DAY);
61966197

61976198
// Scale nanos since midnight to the desired scale, rounding the value as necessary
6198-
divisor = Nanos.PER_MAX_SCALE_INTERVAL * (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - scale);
6199+
divisor = Nanos.PER_MAX_SCALE_INTERVAL
6200+
* (long) Math.pow(10, TDS.MAX_FRACTIONAL_SECONDS_SCALE - (double) scale);
61996201

62006202
// The scaledNanos variable represents the fractional seconds of the value at the scale
62016203
// indicated by the scale variable. So, for example, scaledNanos = 3 means 300 nanoseconds

src/main/java/com/microsoft/sqlserver/jdbc/IdleConnectionResiliency.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public void run() {
469469
} else {
470470
try {
471471
if (connectRetryCount > 1) {
472-
Thread.sleep(con.getRetryInterval() * 1000);
472+
Thread.sleep((long) (con.getRetryInterval()) * 1000);
473473
}
474474
} catch (InterruptedException ie) {
475475
// re-interrupt thread

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ private int findColumn(String columnName) throws SQLServerException {
13651365

13661366
// 1. Search using case-sensitive non-locale specific (binary) compare first.
13671367
// 2. Search using case-insensitive, non-locale specific (binary) compare last.
1368-
Integer matchPos = parameterNames.get(columnNameWithSign);
1368+
Integer matchPos = (parameterNames != null) ? parameterNames.get(columnNameWithSign) : null;
13691369
if (null == matchPos) {
13701370
matchPos = insensitiveParameterNames.get(columnNameWithSign);
13711371
}

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,11 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial
218218
* lock instance for "this"
219219
**/
220220
private final Lock lock = new ReentrantLock();
221+
221222
/**
222223
* static lock instance for the class
223224
**/
224-
private static final Lock LOCK = new ReentrantLock();
225+
private static final Lock sLock = new ReentrantLock();
225226

226227
/**
227228
* Return an existing cached SharedTimer associated with this Connection or create a new one.
@@ -938,7 +939,7 @@ public static void registerColumnEncryptionKeyStoreProviders(
938939
loggerExternal.entering(loggingClassNameBase, "registerColumnEncryptionKeyStoreProviders",
939940
"Registering Column Encryption Key Store Providers");
940941

941-
LOCK.lock();
942+
sLock.lock();
942943
try {
943944
if (null == clientKeyStoreProviders) {
944945
throw new SQLServerException(null, SQLServerException.getErrString("R_CustomKeyStoreProviderMapNull"),
@@ -979,7 +980,7 @@ public static void registerColumnEncryptionKeyStoreProviders(
979980
globalCustomColumnEncryptionKeyStoreProviders.put(providerName, provider);
980981
}
981982
} finally {
982-
LOCK.unlock();
983+
sLock.unlock();
983984
}
984985

985986
loggerExternal.exiting(loggingClassNameBase, "registerColumnEncryptionKeyStoreProviders",
@@ -995,14 +996,14 @@ public static void unregisterColumnEncryptionKeyStoreProviders() {
995996
loggerExternal.entering(loggingClassNameBase, "unregisterColumnEncryptionKeyStoreProviders",
996997
"Removing Column Encryption Key Store Provider");
997998

998-
LOCK.lock();
999+
sLock.lock();
9991000
try {
10001001
if (null != globalCustomColumnEncryptionKeyStoreProviders) {
10011002
globalCustomColumnEncryptionKeyStoreProviders.clear();
10021003
globalCustomColumnEncryptionKeyStoreProviders = null;
10031004
}
10041005
} finally {
1005-
LOCK.unlock();
1006+
sLock.unlock();
10061007
}
10071008

10081009
loggerExternal.exiting(loggingClassNameBase, "unregisterColumnEncryptionKeyStoreProviders",
@@ -1224,15 +1225,15 @@ public static void setColumnEncryptionTrustedMasterKeyPaths(Map<String, List<Str
12241225
loggerExternal.entering(loggingClassNameBase, "setColumnEncryptionTrustedMasterKeyPaths",
12251226
"Setting Trusted Master Key Paths");
12261227

1227-
LOCK.lock();
1228+
sLock.lock();
12281229
try {
12291230
// Use upper case for server and instance names.
12301231
columnEncryptionTrustedMasterKeyPaths.clear();
12311232
for (Map.Entry<String, List<String>> entry : trustedKeyPaths.entrySet()) {
12321233
columnEncryptionTrustedMasterKeyPaths.put(entry.getKey().toUpperCase(), entry.getValue());
12331234
}
12341235
} finally {
1235-
LOCK.unlock();
1236+
sLock.unlock();
12361237
}
12371238

12381239
loggerExternal.exiting(loggingClassNameBase, "setColumnEncryptionTrustedMasterKeyPaths",
@@ -1251,12 +1252,12 @@ public static void updateColumnEncryptionTrustedMasterKeyPaths(String server, Li
12511252
loggerExternal.entering(loggingClassNameBase, "updateColumnEncryptionTrustedMasterKeyPaths",
12521253
"Updating Trusted Master Key Paths");
12531254

1254-
LOCK.lock();
1255+
sLock.lock();
12551256
try {
12561257
// Use upper case for server and instance names.
12571258
columnEncryptionTrustedMasterKeyPaths.put(server.toUpperCase(), trustedKeyPaths);
12581259
} finally {
1259-
LOCK.unlock();
1260+
sLock.unlock();
12601261
}
12611262

12621263
loggerExternal.exiting(loggingClassNameBase, "updateColumnEncryptionTrustedMasterKeyPaths",
@@ -1273,12 +1274,12 @@ public static void removeColumnEncryptionTrustedMasterKeyPaths(String server) {
12731274
loggerExternal.entering(loggingClassNameBase, "removeColumnEncryptionTrustedMasterKeyPaths",
12741275
"Removing Trusted Master Key Paths");
12751276

1276-
LOCK.lock();
1277+
sLock.lock();
12771278
try {
12781279
// Use upper case for server and instance names.
12791280
columnEncryptionTrustedMasterKeyPaths.remove(server.toUpperCase());
12801281
} finally {
1281-
LOCK.unlock();
1282+
sLock.unlock();
12821283
}
12831284

12841285
loggerExternal.exiting(loggingClassNameBase, "removeColumnEncryptionTrustedMasterKeyPaths",
@@ -1294,7 +1295,7 @@ public static Map<String, List<String>> getColumnEncryptionTrustedMasterKeyPaths
12941295
loggerExternal.entering(loggingClassNameBase, "getColumnEncryptionTrustedMasterKeyPaths",
12951296
"Getting Trusted Master Key Paths");
12961297

1297-
LOCK.lock();
1298+
sLock.lock();
12981299
try {
12991300
Map<String, List<String>> masterKeyPathCopy = new HashMap<>();
13001301

@@ -1307,12 +1308,12 @@ public static Map<String, List<String>> getColumnEncryptionTrustedMasterKeyPaths
13071308

13081309
return masterKeyPathCopy;
13091310
} finally {
1310-
LOCK.unlock();
1311+
sLock.unlock();
13111312
}
13121313
}
13131314

13141315
static List<String> getColumnEncryptionTrustedMasterKeyPaths(String server, Boolean[] hasEntry) {
1315-
LOCK.lock();
1316+
sLock.lock();
13161317
try {
13171318
if (columnEncryptionTrustedMasterKeyPaths.containsKey(server)) {
13181319
hasEntry[0] = true;
@@ -1322,7 +1323,7 @@ static List<String> getColumnEncryptionTrustedMasterKeyPaths(String server, Bool
13221323
return null;
13231324
}
13241325
} finally {
1325-
LOCK.unlock();
1326+
sLock.unlock();
13261327
}
13271328
}
13281329

@@ -1331,11 +1332,11 @@ static List<String> getColumnEncryptionTrustedMasterKeyPaths(String server, Bool
13311332
* request to acquire an access token.
13321333
*/
13331334
public static void clearUserTokenCache() {
1334-
LOCK.lock();
1335+
sLock.lock();
13351336
try {
13361337
PersistentTokenCacheAccessAspect.clearUserTokenCache();
13371338
} finally {
1338-
LOCK.unlock();
1339+
sLock.unlock();
13391340
}
13401341
}
13411342

@@ -7469,7 +7470,7 @@ void doSecurityCheck() {
74697470
*/
74707471
public static void setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTTL,
74717472
TimeUnit unit) throws SQLServerException {
7472-
LOCK.lock();
7473+
sLock.lock();
74737474
try {
74747475
if (columnEncryptionKeyCacheTTL < 0 || unit.equals(TimeUnit.MILLISECONDS)
74757476
|| unit.equals(TimeUnit.MICROSECONDS) || unit.equals(TimeUnit.NANOSECONDS)) {
@@ -7479,16 +7480,16 @@ public static void setColumnEncryptionKeyCacheTtl(int columnEncryptionKeyCacheTT
74797480

74807481
columnEncryptionKeyCacheTtl = TimeUnit.SECONDS.convert(columnEncryptionKeyCacheTTL, unit);
74817482
} finally {
7482-
LOCK.unlock();
7483+
sLock.unlock();
74837484
}
74847485
}
74857486

74867487
static long getColumnEncryptionKeyCacheTtl() {
7487-
LOCK.lock();
7488+
sLock.lock();
74887489
try {
74897490
return columnEncryptionKeyCacheTtl;
74907491
} finally {
7491-
LOCK.unlock();
7492+
sLock.unlock();
74927493
}
74937494
}
74947495

0 commit comments

Comments
 (0)