@@ -1138,7 +1138,7 @@ private boolean isBooleanPropertyOn(String propName, String propValue) throws SQ
1138
1138
* the value of the property.
1139
1139
* @throws SQLServerException
1140
1140
*/
1141
- void ValidateMaxSQLLoginName (String propName , String propValue ) throws SQLServerException {
1141
+ void validateMaxSQLLoginName (String propName , String propValue ) throws SQLServerException {
1142
1142
if (propValue != null && propValue .length () > MAX_SQL_LOGIN_NAME_WCHARS ) {
1143
1143
MessageFormat form = new MessageFormat (SQLServerException .getErrString ("R_propertyMaximumExceedsChars" ));
1144
1144
Object [] msgArgs = {propName , Integer .toString (MAX_SQL_LOGIN_NAME_WCHARS )};
@@ -1172,7 +1172,9 @@ Connection connect(Properties propsIn, SQLServerPooledConnection pooledConnectio
1172
1172
String sPropValue = propsIn .getProperty (SQLServerDriverIntProperty .LOGIN_TIMEOUT .toString ());
1173
1173
if (null != sPropValue && sPropValue .length () > 0 ) {
1174
1174
int sPropValueInt = Integer .parseInt (sPropValue );
1175
- loginTimeoutSeconds = 0 != sPropValueInt ? sPropValueInt : loginTimeoutSeconds ;
1175
+ if (0 != sPropValueInt ) { // Use the default timeout in case of a zero value
1176
+ loginTimeoutSeconds = sPropValueInt ;
1177
+ }
1176
1178
}
1177
1179
}
1178
1180
@@ -1289,19 +1291,19 @@ Connection connectInternal(Properties propsIn,
1289
1291
sPropValue = SQLServerDriverStringProperty .USER .getDefaultValue ();
1290
1292
activeConnectionProperties .setProperty (sPropKey , sPropValue );
1291
1293
}
1292
- ValidateMaxSQLLoginName (sPropKey , sPropValue );
1294
+ validateMaxSQLLoginName (sPropKey , sPropValue );
1293
1295
1294
1296
sPropKey = SQLServerDriverStringProperty .PASSWORD .toString ();
1295
1297
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1296
1298
if (sPropValue == null ) {
1297
1299
sPropValue = SQLServerDriverStringProperty .PASSWORD .getDefaultValue ();
1298
1300
activeConnectionProperties .setProperty (sPropKey , sPropValue );
1299
1301
}
1300
- ValidateMaxSQLLoginName (sPropKey , sPropValue );
1302
+ validateMaxSQLLoginName (sPropKey , sPropValue );
1301
1303
1302
1304
sPropKey = SQLServerDriverStringProperty .DATABASE_NAME .toString ();
1303
1305
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1304
- ValidateMaxSQLLoginName (sPropKey , sPropValue );
1306
+ validateMaxSQLLoginName (sPropKey , sPropValue );
1305
1307
1306
1308
// if the user does not specify a default timeout, default is 15 per spec
1307
1309
int loginTimeoutSeconds = SQLServerDriverIntProperty .LOGIN_TIMEOUT .getDefaultValue ();
@@ -1337,7 +1339,9 @@ Connection connectInternal(Properties propsIn,
1337
1339
sPropKey = SQLServerDriverStringProperty .SERVER_NAME .toString ();
1338
1340
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1339
1341
1340
- sPropValue = null == sPropValue ? "localhost" : sPropValue ;
1342
+ if (sPropValue == null ) {
1343
+ sPropValue = "localhost" ;
1344
+ }
1341
1345
1342
1346
String sPropKeyPort = SQLServerDriverIntProperty .PORT_NUMBER .toString ();
1343
1347
String sPropValuePort = activeConnectionProperties .getProperty (sPropKeyPort );
@@ -1350,7 +1354,7 @@ Connection connectInternal(Properties propsIn,
1350
1354
// found the instance name with the servername
1351
1355
if (px >= 0 ) {
1352
1356
instanceValue = sPropValue .substring (px + 1 , sPropValue .length ());
1353
- ValidateMaxSQLLoginName (instanceNameProperty , instanceValue );
1357
+ validateMaxSQLLoginName (instanceNameProperty , instanceValue );
1354
1358
sPropValue = sPropValue .substring (0 , px );
1355
1359
}
1356
1360
trustedServerNameAE = sPropValue ;
@@ -1373,19 +1377,20 @@ Connection connectInternal(Properties propsIn,
1373
1377
instanceValue = instanceValueFromProp ;
1374
1378
1375
1379
if (instanceValue != null ) {
1376
- ValidateMaxSQLLoginName (instanceNameProperty , instanceValue );
1380
+ validateMaxSQLLoginName (instanceNameProperty , instanceValue );
1377
1381
// only get port if the port is not specified
1378
1382
activeConnectionProperties .setProperty (instanceNameProperty , instanceValue );
1379
1383
trustedServerNameAE += "\\ " + instanceValue ;
1380
1384
}
1381
1385
1382
- trustedServerNameAE = null != sPropValuePort ? trustedServerNameAE + ":" + sPropValuePort
1383
- : trustedServerNameAE ;
1386
+ if (null != sPropValuePort ) {
1387
+ trustedServerNameAE += ":" + sPropValuePort ;
1388
+ }
1384
1389
1385
1390
sPropKey = SQLServerDriverStringProperty .APPLICATION_NAME .toString ();
1386
1391
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1387
1392
if (sPropValue != null )
1388
- ValidateMaxSQLLoginName (sPropKey , sPropValue );
1393
+ validateMaxSQLLoginName (sPropKey , sPropValue );
1389
1394
else
1390
1395
activeConnectionProperties .setProperty (sPropKey , SQLServerDriver .DEFAULT_APP_NAME );
1391
1396
@@ -1406,16 +1411,21 @@ Connection connectInternal(Properties propsIn,
1406
1411
1407
1412
sPropKey = SQLServerDriverStringProperty .KEY_STORE_AUTHENTICATION .toString ();
1408
1413
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1409
- keyStoreAuthentication = null != sPropValue ? KeyStoreAuthentication .valueOfString (sPropValue ).toString ()
1410
- : keyStoreAuthentication ;
1414
+ if (null != sPropValue ) {
1415
+ keyStoreAuthentication = KeyStoreAuthentication .valueOfString (sPropValue ).toString ();
1416
+ }
1411
1417
1412
1418
sPropKey = SQLServerDriverStringProperty .KEY_STORE_SECRET .toString ();
1413
1419
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1414
- keyStoreSecret = null != sPropValue ? sPropValue : keyStoreSecret ;
1420
+ if (null != sPropValue ) {
1421
+ keyStoreSecret = sPropValue ;
1422
+ }
1415
1423
1416
1424
sPropKey = SQLServerDriverStringProperty .KEY_STORE_LOCATION .toString ();
1417
1425
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1418
- keyStoreLocation = null != sPropValue ? sPropValue : keyStoreLocation ;
1426
+ if (null != sPropValue ) {
1427
+ keyStoreLocation = sPropValue ;
1428
+ }
1419
1429
1420
1430
registerKeyStoreProviderOnConnection (keyStoreAuthentication , keyStoreSecret , keyStoreLocation );
1421
1431
@@ -1464,8 +1474,9 @@ Connection connectInternal(Properties propsIn,
1464
1474
1465
1475
sPropKey = SQLServerDriverStringProperty .SELECT_METHOD .toString ();
1466
1476
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1467
- sPropValue = sPropValue == null ? SQLServerDriverStringProperty .SELECT_METHOD .getDefaultValue ()
1468
- : sPropValue ;
1477
+ if (sPropValue == null ) {
1478
+ sPropValue = SQLServerDriverStringProperty .SELECT_METHOD .getDefaultValue ();
1479
+ }
1469
1480
1470
1481
if ("cursor" .equalsIgnoreCase (sPropValue ) || "direct" .equalsIgnoreCase (sPropValue )) {
1471
1482
sPropValue = sPropValue .toLowerCase (Locale .ENGLISH );
@@ -1479,8 +1490,9 @@ Connection connectInternal(Properties propsIn,
1479
1490
1480
1491
sPropKey = SQLServerDriverStringProperty .RESPONSE_BUFFERING .toString ();
1481
1492
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1482
- sPropValue = sPropValue == null ? SQLServerDriverStringProperty .RESPONSE_BUFFERING .getDefaultValue ()
1483
- : sPropValue ;
1493
+ if (sPropValue == null ) {
1494
+ sPropValue = SQLServerDriverStringProperty .RESPONSE_BUFFERING .getDefaultValue ();
1495
+ }
1484
1496
1485
1497
if ("full" .equalsIgnoreCase (sPropValue ) || "adaptive" .equalsIgnoreCase (sPropValue )) {
1486
1498
activeConnectionProperties .setProperty (sPropKey , sPropValue .toLowerCase (Locale .ENGLISH ));
@@ -1492,8 +1504,9 @@ Connection connectInternal(Properties propsIn,
1492
1504
1493
1505
sPropKey = SQLServerDriverStringProperty .APPLICATION_INTENT .toString ();
1494
1506
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1495
- sPropValue = sPropValue == null ? SQLServerDriverStringProperty .APPLICATION_INTENT .getDefaultValue ()
1496
- : sPropValue ;
1507
+ if (sPropValue == null ) {
1508
+ sPropValue = SQLServerDriverStringProperty .APPLICATION_INTENT .getDefaultValue ();
1509
+ }
1497
1510
1498
1511
applicationIntent = ApplicationIntent .valueOfString (sPropValue );
1499
1512
activeConnectionProperties .setProperty (sPropKey , applicationIntent .toString ());
@@ -1531,13 +1544,17 @@ Connection connectInternal(Properties propsIn,
1531
1544
1532
1545
sPropKey = SQLServerDriverBooleanProperty .INTEGRATED_SECURITY .toString ();
1533
1546
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1534
- integratedSecurity = sPropValue != null ? isBooleanPropertyOn (sPropKey , sPropValue ) : integratedSecurity ;
1547
+ if (sPropValue != null ) {
1548
+ integratedSecurity = isBooleanPropertyOn (sPropKey , sPropValue );
1549
+ }
1535
1550
1536
1551
// Ignore authenticationScheme setting if integrated authentication not specified
1537
1552
if (integratedSecurity ) {
1538
1553
sPropKey = SQLServerDriverStringProperty .AUTHENTICATION_SCHEME .toString ();
1539
1554
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1540
- intAuthScheme = sPropValue != null ? AuthenticationScheme .valueOfString (sPropValue ) : intAuthScheme ;
1555
+ if (sPropValue != null ) {
1556
+ intAuthScheme = AuthenticationScheme .valueOfString (sPropValue );
1557
+ }
1541
1558
}
1542
1559
1543
1560
if (intAuthScheme == AuthenticationScheme .javaKerberos ) {
@@ -1550,8 +1567,9 @@ Connection connectInternal(Properties propsIn,
1550
1567
1551
1568
sPropKey = SQLServerDriverStringProperty .AUTHENTICATION .toString ();
1552
1569
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1553
- sPropValue = sPropValue == null ? SQLServerDriverStringProperty .AUTHENTICATION .getDefaultValue ()
1554
- : sPropValue ;
1570
+ if (sPropValue == null ) {
1571
+ sPropValue = SQLServerDriverStringProperty .AUTHENTICATION .getDefaultValue ();
1572
+ }
1555
1573
authenticationString = SqlAuthentication .valueOfString (sPropValue ).toString ().trim ();
1556
1574
1557
1575
if (integratedSecurity
@@ -1617,7 +1635,9 @@ Connection connectInternal(Properties propsIn,
1617
1635
1618
1636
sPropKey = SQLServerDriverStringProperty .ACCESS_TOKEN .toString ();
1619
1637
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1620
- accessTokenInByte = null != sPropValue ? sPropValue .getBytes (UTF_16LE ) : accessTokenInByte ;
1638
+ if (null != sPropValue ) {
1639
+ accessTokenInByte = sPropValue .getBytes (UTF_16LE );
1640
+ }
1621
1641
1622
1642
if ((null != accessTokenInByte ) && 0 == accessTokenInByte .length ) {
1623
1643
if (connectionlogger .isLoggable (Level .SEVERE )) {
@@ -1665,7 +1685,7 @@ Connection connectInternal(Properties propsIn,
1665
1685
1666
1686
sPropKey = SQLServerDriverStringProperty .WORKSTATION_ID .toString ();
1667
1687
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1668
- ValidateMaxSQLLoginName (sPropKey , sPropValue );
1688
+ validateMaxSQLLoginName (sPropKey , sPropValue );
1669
1689
1670
1690
int nPort = 0 ;
1671
1691
sPropKey = SQLServerDriverIntProperty .PORT_NUMBER .toString ();
@@ -1849,8 +1869,9 @@ else if (0 == requestedPacketSize)
1849
1869
1850
1870
sPropKey = SQLServerDriverBooleanProperty .USE_BULK_COPY_FOR_BATCH_INSERT .toString ();
1851
1871
sPropValue = activeConnectionProperties .getProperty (sPropKey );
1852
- useBulkCopyForBatchInsert = null != sPropValue ? isBooleanPropertyOn (sPropKey , sPropValue )
1853
- : useBulkCopyForBatchInsert ;
1872
+ if (null != sPropValue ) {
1873
+ useBulkCopyForBatchInsert = isBooleanPropertyOn (sPropKey , sPropValue );
1874
+ }
1854
1875
1855
1876
sPropKey = SQLServerDriverStringProperty .SSL_PROTOCOL .toString ();
1856
1877
sPropValue = activeConnectionProperties .getProperty (sPropKey );
@@ -2052,9 +2073,9 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
2052
2073
}
2053
2074
2054
2075
// Attempt login. Use Place holder to make sure that the failoverdemand is done.
2055
- connectHelper (currentConnectPlaceHolder , TimerRemaining (intervalExpire ), timeout , useParallel , useTnir ,
2076
+ connectHelper (currentConnectPlaceHolder , timerRemaining (intervalExpire ), timeout , useParallel , useTnir ,
2056
2077
(0 == attemptNumber ), // is this the TNIR first attempt
2057
- TimerRemaining (intervalExpireFullTimeout )); // Only used when host resolves to >64 IPs
2078
+ timerRemaining (intervalExpireFullTimeout )); // Only used when host resolves to >64 IPs
2058
2079
2059
2080
if (isRoutedInCurrentAttempt ) {
2060
2081
// we ignore the failoverpartner ENVCHANGE if we got routed so no error needs to be thrown
@@ -2156,7 +2177,7 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
2156
2177
if (!isDBMirroring || 1 == attemptNumber % 2 ) {
2157
2178
// Check sleep interval to make sure we won't exceed the timeout
2158
2179
// Do this in the catch block so we can re-throw the current exception
2159
- long remainingMilliseconds = TimerRemaining (timerExpire );
2180
+ long remainingMilliseconds = timerRemaining (timerExpire );
2160
2181
if (remainingMilliseconds <= sleepInterval ) {
2161
2182
throw sqlex ;
2162
2183
}
@@ -2202,10 +2223,14 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
2202
2223
// Due to the below condition and the timerHasExpired check in catch block,
2203
2224
// the multiSubnetFailover case or any other standardLogin case where timeOutInterval is full timeout would
2204
2225
// also be handled correctly.
2205
- intervalExpire = intervalExpire > timerExpire ? timerExpire : intervalExpire ;
2226
+ if (intervalExpire > timerExpire ) {
2227
+ intervalExpire = timerExpire ;
2228
+ }
2206
2229
2207
2230
// try again, this time swapping primary/secondary servers
2208
- useFailoverHost = isDBMirroring ? !useFailoverHost : useFailoverHost ;
2231
+ if (isDBMirroring ) {
2232
+ useFailoverHost = !useFailoverHost ;
2233
+ }
2209
2234
}
2210
2235
2211
2236
// If we get here, connection/login succeeded! Just a few more checks & record-keeping
@@ -2324,13 +2349,16 @@ static boolean timerHasExpired(long timerExpire) {
2324
2349
return System .currentTimeMillis () > timerExpire ;
2325
2350
}
2326
2351
2327
- static int TimerRemaining (long timerExpire ) {
2328
- long result = timerExpire - System .currentTimeMillis ();
2329
- // maximum timeout the socket takes is int max.
2330
- result = result > Integer .MAX_VALUE ? Integer .MAX_VALUE : result ;
2331
- // we have to make sure that we return at least one ms
2332
- // we want at least one attempt to happen with a positive timeout passed by the user.
2333
- return result <= 0 ? 1 : (int ) result ;
2352
+ /**
2353
+ * Get time remaining to timer expiry
2354
+ *
2355
+ * @param timerExpire
2356
+ * @return remaining time to expiry
2357
+ */
2358
+ static int timerRemaining (long timerExpire ) {
2359
+ long remaining = timerExpire - System .currentTimeMillis ();
2360
+ // maximum timeout the socket takes is int max, minimum is at least 1 ms
2361
+ return (int ) ((remaining > Integer .MAX_VALUE ) ? Integer .MAX_VALUE : (remaining <= 0 ) ? 1 : remaining );
2334
2362
}
2335
2363
2336
2364
/**
@@ -2366,7 +2394,9 @@ private void connectHelper(ServerPortPlaceHolder serverInfo, int timeOutsliceInM
2366
2394
// as the InetAddress.getLocalHost() takes more than usual time in certain OS and JVM combination, it avoids
2367
2395
// connection loss
2368
2396
hostName = activeConnectionProperties .getProperty (SQLServerDriverStringProperty .WORKSTATION_ID .toString ());
2369
- hostName = StringUtils .isEmpty (hostName ) ? Util .lookupHostName () : hostName ;
2397
+ if (StringUtils .isEmpty (hostName )) {
2398
+ hostName = Util .lookupHostName ();
2399
+ }
2370
2400
2371
2401
// if the timeout is infinite slices are infinite too.
2372
2402
tdsChannel = new TDSChannel (this );
@@ -4114,7 +4144,7 @@ private SqlFedAuthToken getFedAuthToken(SqlFedAuthInfo fedAuthInfo) throws SQLSe
4114
4144
throw new SQLServerException (form .format (msgArgs ), null );
4115
4145
}
4116
4146
4117
- int millisecondsRemaining = TimerRemaining (timerExpire );
4147
+ int millisecondsRemaining = timerRemaining (timerExpire );
4118
4148
if (ActiveDirectoryAuthentication .GET_ACCESS_TOKEN_TANSISENT_ERROR != errorCategory
4119
4149
|| timerHasExpired (timerExpire ) || (sleepInterval >= millisecondsRemaining )) {
4120
4150
@@ -4704,7 +4734,9 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
4704
4734
: activeConnectionProperties .getProperty (
4705
4735
SQLServerDriverStringProperty .SERVER_NAME
4706
4736
.toString ());
4707
- serverName = (serverName != null && serverName .length () > 128 ) ? serverName .substring (0 , 128 ) : serverName ;
4737
+ if (serverName != null && serverName .length () > 128 ) {
4738
+ serverName = serverName .substring (0 , 128 );
4739
+ }
4708
4740
4709
4741
byte [] secBlob = new byte [0 ];
4710
4742
boolean [] done = {false };
@@ -4798,16 +4830,10 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
4798
4830
{
4799
4831
colEncSetting = TDS .LOGIN_OPTION3_FEATURE_EXTENSION ;
4800
4832
}
4833
+
4834
+ // Accept unknown collations from Katmai & later servers
4801
4835
tdsWriter .writeByte ((byte ) (TDS .LOGIN_OPTION3_DEFAULT | colEncSetting
4802
- | ((serverMajorVersion >= 10 ) ? TDS .LOGIN_OPTION3_UNKNOWN_COLLATION_HANDLING : 0 ) // Accept
4803
- // unknown
4804
- // collations
4805
- // from
4806
- // Katmai
4807
- // &
4808
- // later
4809
- // servers
4810
- ));
4836
+ | ((serverMajorVersion >= 10 ) ? TDS .LOGIN_OPTION3_UNKNOWN_COLLATION_HANDLING : 0 )));
4811
4837
4812
4838
tdsWriter .writeInt ((byte ) 0 ); // Client time zone
4813
4839
tdsWriter .writeInt ((byte ) 0 ); // Client LCID
0 commit comments