Skip to content

Commit

Permalink
Fix code cleanups (#1441)
Browse files Browse the repository at this point in the history
* Fix immutable properties

It was intentionally designed the previous way

* Restore limit in for loop

* Another ImmutableProperties
  • Loading branch information
ZacSweers committed Dec 1, 2021
1 parent 9f81ac8 commit 751e821
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Expand Up @@ -436,7 +436,10 @@ class GeneratedAdaptersTest {
}

@JsonClass(generateAdapter = true)
class ImmutableProperties(val a: Int, val b: Int)
class ImmutableProperties(a: Int, b: Int) {
val a = a
val b = b
}

@Test fun constructorDefaults() {
val moshi = Moshi.Builder().build()
Expand Down
Expand Up @@ -115,7 +115,10 @@ class KotlinJsonAdapterTest {
assertThat(decoded.b).isEqualTo(5)
}

class ImmutableProperties(val a: Int, val b: Int)
class ImmutableProperties(a: Int, b: Int) {
val a = a
val b = b
}

@Test fun constructorDefaults() {
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
Expand Down
2 changes: 1 addition & 1 deletion moshi/src/main/java/com/squareup/moshi/Moshi.java
Expand Up @@ -185,7 +185,7 @@ public <T> JsonAdapter<T> nextAdapter(
@CheckReturnValue
public Moshi.Builder newBuilder() {
Builder result = new Builder();
for (int i = 0; i < lastOffset; i++) {
for (int i = 0, limit = lastOffset; i < limit; i++) {
result.add(factories.get(i));
}
for (int i = lastOffset, limit = factories.size() - BUILT_IN_FACTORIES.size(); i < limit; i++) {
Expand Down

0 comments on commit 751e821

Please sign in to comment.