Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More code clean up to fix SonarQube issues #1977

Merged
merged 11 commits into from
Dec 22, 2022
17 changes: 12 additions & 5 deletions src/main/java/com/microsoft/sqlserver/jdbc/DDC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ static final Object convertTemporalToObject(JDBCType jdbcType, SSType ssType, Ca
ts.setNanos(subSecondNanos);
return ts;

case DATETIMEOFFSET: {
case DATETIMEOFFSET:
// Per driver spec, conversion to DateTimeOffset is only supported from
// DATETIMEOFFSET SQL Server values.
assert SSType.DATETIMEOFFSET == ssType;
Expand All @@ -1070,7 +1070,6 @@ static final Object convertTemporalToObject(JDBCType jdbcType, SSType ssType, Ca
java.sql.Timestamp ts1 = new java.sql.Timestamp(cal.getTimeInMillis());
ts1.setNanos(subSecondNanos);
return microsoft.sql.DateTimeOffset.valueOf(ts1, localMillisOffset / (60 * 1000));
}

case TIME:
// Per driver spec, values of sql server data types types (including TIME) which have greater
Expand Down Expand Up @@ -1484,7 +1483,11 @@ public int read() throws IOException {
public int read(byte[] b) throws IOException {
int bytesRead = containedStream.read(b);
if (bytesRead > 0) {
assert bytesRead <= b.length;
if (bytesRead > b.length) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_mismatchedStreamLength"));
throw new IOException(form.format(new Object[] {b.length, bytesRead}));
}

for (int i = 0; i < bytesRead; i++)
b[i] = ASCII_FILTER[b[i] & 0xFF];
}
Expand All @@ -1495,7 +1498,11 @@ public int read(byte[] b) throws IOException {
public int read(byte[] b, int offset, int maxBytes) throws IOException {
int bytesRead = containedStream.read(b, offset, maxBytes);
if (bytesRead > 0) {
assert offset + bytesRead <= b.length;
if (offset + bytesRead > b.length) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_mismatchedStreamLength"));
throw new IOException(form.format(new Object[] {b.length, bytesRead}));
}

for (int i = 0; i < bytesRead; i++)
b[offset + i] = ASCII_FILTER[b[offset + i] & 0xFF];
}
Expand Down Expand Up @@ -1574,7 +1581,7 @@ public int read(byte[] b) throws IOException {
}

@Override
public int read(byte b[], int offset, int maxBytes) throws IOException {
public int read(byte[] b, int offset, int maxBytes) throws IOException {
char[] tempBufferToHoldCharDataForConversion = new char[maxBytes];
int charsRead = containedReader.read(tempBufferToHoldCharDataForConversion);

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/microsoft/sqlserver/jdbc/DataTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1179,12 +1179,10 @@ static final long getCheckedLength(SQLServerConnection con, JDBCType jdbcType, l
case NVARCHAR:
case LONGNVARCHAR:
case NCLOB:
// assert MAX_VARTYPE_MAX_CHARS == NTEXT_MAX_CHARS;
maxLength = DataTypes.MAX_VARTYPE_MAX_CHARS;
break;

default:
// assert MAX_VARTYPE_MAX_BYTES == IMAGE_TEXT_MAX_BYTES;
maxLength = DataTypes.MAX_VARTYPE_MAX_BYTES;
break;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/microsoft/sqlserver/jdbc/Geography.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ protected Geography(byte[] clr) throws SQLServerException {

parseClr(this);

WKTsb = new StringBuffer();
WKTsbNoZM = new StringBuffer();
wktSb = new StringBuffer();
wktSbNoZM = new StringBuffer();

constructWKT(this, internalType, numberOfPoints, numberOfFigures, numberOfSegments, numberOfShapes);

wkt = WKTsb.toString();
wktNoZM = WKTsbNoZM.toString();
wkt = wktSb.toString();
wktNoZM = wktSbNoZM.toString();
isNull = false;
}

Expand Down Expand Up @@ -165,10 +165,10 @@ public String STAsText() throws SQLServerException {

parseClr(this);

WKTsb = new StringBuffer();
WKTsbNoZM = new StringBuffer();
wktSb = new StringBuffer();
wktSbNoZM = new StringBuffer();
constructWKT(this, internalType, numberOfPoints, numberOfFigures, numberOfSegments, numberOfShapes);
wktNoZM = WKTsbNoZM.toString();
wktNoZM = wktSbNoZM.toString();
}
return wktNoZM;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/microsoft/sqlserver/jdbc/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ protected Geometry(byte[] clr) throws SQLServerException {

parseClr(this);

WKTsb = new StringBuffer();
WKTsbNoZM = new StringBuffer();
wktSb = new StringBuffer();
wktSbNoZM = new StringBuffer();

constructWKT(this, internalType, numberOfPoints, numberOfFigures, numberOfSegments, numberOfShapes);

wkt = WKTsb.toString();
wktNoZM = WKTsbNoZM.toString();
wkt = wktSb.toString();
wktNoZM = wktSbNoZM.toString();
isNull = false;
}

Expand Down Expand Up @@ -169,10 +169,10 @@ public String STAsText() throws SQLServerException {

parseClr(this);

WKTsb = new StringBuffer();
WKTsbNoZM = new StringBuffer();
wktSb = new StringBuffer();
wktSbNoZM = new StringBuffer();
constructWKT(this, internalType, numberOfPoints, numberOfFigures, numberOfSegments, numberOfShapes);
wktNoZM = WKTsbNoZM.toString();
wktNoZM = wktSbNoZM.toString();
}
return wktNoZM;
}
Expand Down
Loading