Skip to content

Commit

Permalink
Tackle code quality issues (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
jodastephen authored Aug 24, 2022
1 parent eb9644e commit 12559d7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/joda/time/Period.java
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ public Period normalizedStandard(PeriodType type) {
if (type.isSupported(DurationFieldType.YEARS_TYPE)) {
int normalizedYears = FieldUtils.safeToInt(totalMonths / 12);
result = result.withYears(normalizedYears);
totalMonths = totalMonths - (normalizedYears * 12);
totalMonths = totalMonths - (normalizedYears * 12L);
}
if (type.isSupported(DurationFieldType.MONTHS_TYPE)) {
int normalizedMonths = FieldUtils.safeToInt(totalMonths);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/joda/time/chrono/BasicChronology.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ public long getDateTimeMillis(
FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);
long millisOfDay = hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
+ minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
+ secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
long millisOfDay = (long) hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
+ (long) minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
+ (long) secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
+ millisOfSecond;
return getDateTimeMillis0(year, monthOfYear, dayOfMonth, (int) millisOfDay);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,7 @@ public int parseInto(DateTimeParserBucket bucket, CharSequence text, int positio
prefix = text.subSequence(pos, i + 1).toString();
pos += prefix.length();
String prefixLookup = prefix;
if (i < textLen) {
if (i < textLen - 1) {
prefixLookup += text.charAt(i + 1);
}
suffixSet = GROUPED_IDS.get(prefixLookup);
Expand Down Expand Up @@ -2631,7 +2631,7 @@ public int parseInto(DateTimeParserBucket bucket, CharSequence text, int positio
bucket.restoreState(originalState);
}

if (bestValidPos > position || (bestValidPos == position && isOptional)) {
if (bestValidPos > position || (bestValidPos == position && isOptional)) { // LGTM ignore
// Restore the state to the best valid parse.
if (bestValidState != null) {
bucket.restoreState(bestValidState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ long getFieldValue(ReadablePeriod period) {
if (isZero(period) && iFieldFormatters[iFieldType] == this) {
int i = Math.min(iFieldType, 8); // line split out for IBM JDK
i--; // see bug 1660490
for (; i >= 0 && i <= MAX_FIELD; i--) {
for (; i >= 0; i--) {
if (isSupported(type, i) && iFieldFormatters[i] != null) {
return Long.MAX_VALUE;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/joda/time/tz/ZoneInfoCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static void writeZoneInfoMap(DataOutputStream dout, Map<String, DateTimeZone> zi
Short index = Short.valueOf(count);
idToIndex.put(id, index);
indexToId.put(index, id);
if (++count == 0) {
if (++count == Integer.MAX_VALUE) {
throw new InternalError("Too many time zone ids");
}
}
Expand All @@ -177,7 +177,7 @@ static void writeZoneInfoMap(DataOutputStream dout, Map<String, DateTimeZone> zi
Short index = Short.valueOf(count);
idToIndex.put(id, index);
indexToId.put(index, id);
if (++count == 0) {
if (++count == Integer.MAX_VALUE) {
throw new InternalError("Too many time zone ids");
}
}
Expand Down

0 comments on commit 12559d7

Please sign in to comment.