Skip to content

Commit 12559d7

Browse files
authored
Tackle code quality issues (#631)
1 parent eb9644e commit 12559d7

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/main/java/org/joda/time/Period.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ public Period normalizedStandard(PeriodType type) {
16501650
if (type.isSupported(DurationFieldType.YEARS_TYPE)) {
16511651
int normalizedYears = FieldUtils.safeToInt(totalMonths / 12);
16521652
result = result.withYears(normalizedYears);
1653-
totalMonths = totalMonths - (normalizedYears * 12);
1653+
totalMonths = totalMonths - (normalizedYears * 12L);
16541654
}
16551655
if (type.isSupported(DurationFieldType.MONTHS_TYPE)) {
16561656
int normalizedMonths = FieldUtils.safeToInt(totalMonths);

src/main/java/org/joda/time/chrono/BasicChronology.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ public long getDateTimeMillis(
177177
FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
178178
FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
179179
FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);
180-
long millisOfDay = hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
181-
+ minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
182-
+ secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
180+
long millisOfDay = (long) hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
181+
+ (long) minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
182+
+ (long) secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
183183
+ millisOfSecond;
184184
return getDateTimeMillis0(year, monthOfYear, dayOfMonth, (int) millisOfDay);
185185
}

src/main/java/org/joda/time/format/DateTimeFormatterBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,7 @@ public int parseInto(DateTimeParserBucket bucket, CharSequence text, int positio
23822382
prefix = text.subSequence(pos, i + 1).toString();
23832383
pos += prefix.length();
23842384
String prefixLookup = prefix;
2385-
if (i < textLen) {
2385+
if (i < textLen - 1) {
23862386
prefixLookup += text.charAt(i + 1);
23872387
}
23882388
suffixSet = GROUPED_IDS.get(prefixLookup);
@@ -2631,7 +2631,7 @@ public int parseInto(DateTimeParserBucket bucket, CharSequence text, int positio
26312631
bucket.restoreState(originalState);
26322632
}
26332633

2634-
if (bestValidPos > position || (bestValidPos == position && isOptional)) {
2634+
if (bestValidPos > position || (bestValidPos == position && isOptional)) { // LGTM ignore
26352635
// Restore the state to the best valid parse.
26362636
if (bestValidState != null) {
26372637
bucket.restoreState(bestValidState);

src/main/java/org/joda/time/format/PeriodFormatterBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ long getFieldValue(ReadablePeriod period) {
17751775
if (isZero(period) && iFieldFormatters[iFieldType] == this) {
17761776
int i = Math.min(iFieldType, 8); // line split out for IBM JDK
17771777
i--; // see bug 1660490
1778-
for (; i >= 0 && i <= MAX_FIELD; i--) {
1778+
for (; i >= 0; i--) {
17791779
if (isSupported(type, i) && iFieldFormatters[i] != null) {
17801780
return Long.MAX_VALUE;
17811781
}

src/main/java/org/joda/time/tz/ZoneInfoCompiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static void writeZoneInfoMap(DataOutputStream dout, Map<String, DateTimeZone> zi
168168
Short index = Short.valueOf(count);
169169
idToIndex.put(id, index);
170170
indexToId.put(index, id);
171-
if (++count == 0) {
171+
if (++count == Integer.MAX_VALUE) {
172172
throw new InternalError("Too many time zone ids");
173173
}
174174
}
@@ -177,7 +177,7 @@ static void writeZoneInfoMap(DataOutputStream dout, Map<String, DateTimeZone> zi
177177
Short index = Short.valueOf(count);
178178
idToIndex.put(id, index);
179179
indexToId.put(index, id);
180-
if (++count == 0) {
180+
if (++count == Integer.MAX_VALUE) {
181181
throw new InternalError("Too many time zone ids");
182182
}
183183
}

0 commit comments

Comments
 (0)