Skip to content

Commit

Permalink
Merge pull request #301 from v-afrafi/SonarQube_fixes
Browse files Browse the repository at this point in the history
SonarQube fixes
  • Loading branch information
AfsanehR-zz authored May 25, 2017
2 parents 2bad1fb + 137bbea commit 5718b5b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private String escapeParse(StringTokenizer st,
String fullName;
nameFragment = firstToken;
// skip spaces
while (nameFragment.equals(" ") && st.hasMoreTokens()) {
while (" ".equals(nameFragment) && st.hasMoreTokens()) {
nameFragment = st.nextToken();
}
fullName = nameFragment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2209,11 +2209,11 @@ public <T> T unwrap(Class<T> iface) throws SQLException {
public final void setResponseBuffering(String value) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "setResponseBuffering", value);
checkClosed();
if (value.equalsIgnoreCase("full")) {
if ("full".equalsIgnoreCase(value)) {
isResponseBufferingAdaptive = false;
wasResponseBufferingSet = true;
}
else if (value.equalsIgnoreCase("adaptive")) {
else if ("adaptive".equalsIgnoreCase(value)) {
isResponseBufferingAdaptive = true;
wasResponseBufferingSet = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ SQLServerSymmetricKey getKey(EncryptionKeyInfo keyInfo,
String serverName = connection.getTrustedServerNameAE();
assert null != serverName : "serverName should not be null in getKey.";

StringBuffer keyLookupValuebuffer = new StringBuffer(serverName);
String keyLookupValue = null;
StringBuilder keyLookupValuebuffer = new StringBuilder(serverName);
String keyLookupValue;
keyLookupValuebuffer.append(":");

keyLookupValuebuffer.append(DatatypeConverter.printBase64Binary((new String(keyInfo.encryptedKey, UTF_8)).getBytes()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.sql.Statement;
import java.sql.Types;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -791,7 +792,7 @@ else if (-1 != version.indexOf('.')) {
/* L0 */ public Xid[] recover(int flags) throws XAException {
XAReturnValue r = DTC_XA_Interface(XA_RECOVER, null, flags | tightlyCoupled);
int offset = 0;
Vector<XidImpl> v = new Vector<XidImpl>();
ArrayList<XidImpl> al = new ArrayList<XidImpl>();

// If no XID's found, return zero length XID array (don't return null).
//
Expand Down Expand Up @@ -824,11 +825,11 @@ else if (-1 != version.indexOf('.')) {
System.arraycopy(r.bData, offset, bid, 0, bid_len);
offset += bid_len;
XidImpl xid = new XidImpl(formatId, gid, bid);
v.add(xid);
al.add(xid);
}
XidImpl xids[] = new XidImpl[v.size()];
for (int i = 0; i < v.size(); i++) {
xids[i] = v.elementAt(i);
XidImpl xids[] = new XidImpl[al.size()];
for (int i = 0; i < al.size(); i++) {
xids[i] = al.get(i);
if (xaLogger.isLoggable(Level.FINER))
xaLogger.finer(toString() + xids[i].toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public int read(byte b[],
if (isEOS())
return -1;

int readAmount = 0;
int readAmount;
if (streamPos + maxBytes > payloadLength) {
readAmount = payloadLength - streamPos;
}
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/microsoft/sqlserver/jdbc/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ public static boolean isNumeric(final String str) {
* @return {@link Boolean} if provided String is Integer or not.
*/
public static boolean isInteger(final String str) {
boolean isInteger = false;

try {
int i = Integer.parseInt(str);
isInteger = true;
}catch(NumberFormatException e) {
//Nothing. this is not integer.
Integer.parseInt(str);
return true;
}

return isInteger;
catch (NumberFormatException e) {
// Nothing. this is not integer.
}
return false;
}

}
53 changes: 36 additions & 17 deletions src/main/java/com/microsoft/sqlserver/jdbc/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,13 @@ static BigDecimal readBigDecimal(byte valueBytes[],
String result = "";
String name = "";
String value = "";

StringBuilder builder;

if (!tmpUrl.startsWith(sPrefix))
return null;

tmpUrl = tmpUrl.substring(sPrefix.length());
int i = 0;
int i;

// Simple finite state machine.
// always look at one char at a time
Expand All @@ -273,7 +274,10 @@ static BigDecimal readBigDecimal(byte valueBytes[],
state = inName;
}
else {
result = result + ch;
builder = new StringBuilder();
builder.append(result);
builder.append(ch);
result = builder.toString();
state = inServerName;
}
break;
Expand All @@ -299,7 +303,10 @@ else if (ch == ':')
state = inInstanceName;
}
else {
result = result + ch;
builder = new StringBuilder();
builder.append(result);
builder.append(ch);
result = builder.toString();
// same state
}
break;
Expand All @@ -316,7 +323,10 @@ else if (ch == ':')
state = inName;
}
else {
result = result + ch;
builder = new StringBuilder();
builder.append(result);
builder.append(ch);
result = builder.toString();
// same state
}
break;
Expand All @@ -337,7 +347,10 @@ else if (ch == ':')
state = inPort;
}
else {
result = result + ch;
builder = new StringBuilder();
builder.append(result);
builder.append(ch);
result = builder.toString();
// same state
}
break;
Expand All @@ -361,7 +374,10 @@ else if (ch == ':')
// same state
}
else {
name = name + ch;
builder = new StringBuilder();
builder.append(name);
builder.append(ch);
name = builder.toString();
// same state
}
break;
Expand Down Expand Up @@ -398,7 +414,10 @@ else if (ch == '{') {
}
}
else {
value = value + ch;
builder = new StringBuilder();
builder.append(value);
builder.append(ch);
value = builder.toString();
// same state
}
break;
Expand All @@ -423,7 +442,10 @@ else if (ch == '{') {
state = inEscapedValueEnd;
}
else {
value = value + ch;
builder = new StringBuilder();
builder.append(value);
builder.append(ch);
value = builder.toString();
// same state
}
break;
Expand Down Expand Up @@ -728,7 +750,7 @@ static final String readGUID(byte[] inputGUID) throws SQLServerException {
static boolean IsActivityTraceOn() {
LogManager lm = LogManager.getLogManager();
String activityTrace = lm.getProperty(ActivityIdTraceProperty);
if (null != activityTrace && activityTrace.equalsIgnoreCase("on"))
if ("on".equalsIgnoreCase(activityTrace))
return true;
else
return false;
Expand All @@ -746,7 +768,6 @@ static boolean shouldHonorAEForRead(SQLServerStatementColumnEncryptionSetting st
case Disabled:
return false;
case Enabled:
return true;
case ResultSetOnly:
return true;
default:
Expand All @@ -766,11 +787,10 @@ static boolean shouldHonorAEForParameters(SQLServerStatementColumnEncryptionSett
// Command leve setting trumps all
switch (stmtColumnEncryptionSetting) {
case Disabled:
case ResultSetOnly:
return false;
case Enabled:
return true;
case ResultSetOnly:
return false;
default:
// Check connection level setting!
assert SQLServerStatementColumnEncryptionSetting.UseConnectionSetting == stmtColumnEncryptionSetting : "Unexpected value for command level override";
Expand Down Expand Up @@ -849,7 +869,7 @@ else if (JDBCType.BINARY == jdbcType || JDBCType.VARBINARY == jdbcType) {
return ((null == value) ? 0 : ((byte[]) value).length);

case BIGDECIMAL:
int length = -1;
int length;

if (null == precision) {
if (null == value) {
Expand Down Expand Up @@ -891,13 +911,12 @@ else if (("" + value).contains("E")) {
case TIME:
case DATETIMEOFFSET:
return ((null == scale) ? TDS.MAX_FRACTIONAL_SECONDS_SCALE : scale);
case READER:
return ((null == value) ? 0 : DataTypes.NTEXT_MAX_CHARS);


case CLOB:
return ((null == value) ? 0 : (DataTypes.NTEXT_MAX_CHARS * 2));

case NCLOB:
case READER:
return ((null == value) ? 0 : DataTypes.NTEXT_MAX_CHARS);
}
return 0;
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/com/microsoft/sqlserver/jdbc/dtv.java
Original file line number Diff line number Diff line change
Expand Up @@ -1523,10 +1523,7 @@ final void executeOp(DTVExecuteOp op) throws SQLServerException {
case LONGVARCHAR:
case CLOB:
case GUID:
if (null != cryptoMeta)
op.execute(this, (byte[]) null);
else
op.execute(this, (byte[]) null);
op.execute(this, (byte[]) null);
break;

case TINYINT:
Expand Down Expand Up @@ -3540,7 +3537,7 @@ Object denormalizedValue(byte[] decryptedValue,
(null == baseTypeInfo.getCharset()) ? con.getDatabaseCollation().getCharset() : baseTypeInfo.getCharset());
if ((SSType.CHAR == baseSSType) || (SSType.NCHAR == baseSSType)) {
// Right pad the string for CHAR types.
StringBuffer sb = new StringBuffer(strVal);
StringBuilder sb = new StringBuilder(strVal);
int padLength = baseTypeInfo.getPrecision() - strVal.length();
for (int i = 0; i < padLength; i++) {
sb.append(' ');
Expand Down Expand Up @@ -3738,7 +3735,7 @@ Object getValue(DTV dtv,
TDSReader tdsReader) throws SQLServerException {
SQLServerConnection con = tdsReader.getConnection();
Object convertedValue = null;
byte[] decryptedValue = null;
byte[] decryptedValue;
boolean encrypted = false;
SSType baseSSType = typeInfo.getSSType();

Expand All @@ -3765,8 +3762,6 @@ Object getValue(DTV dtv,
// or valueMark should be null and isNull should be set to true(NBCROW case)
assert ((valueMark != null) || (valueMark == null && isNull));

boolean isAdaptive = false;

if (null != streamGetterArgs) {
if (!streamGetterArgs.streamType.convertsFrom(typeInfo))
DataTypes.throwConversionError(typeInfo.getSSType().toString(), streamGetterArgs.streamType.toString());
Expand Down

0 comments on commit 5718b5b

Please sign in to comment.