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

IllegalArgumentException: wrong number of arguments #960

Closed
ber4444 opened this issue Oct 25, 2019 · 21 comments
Closed

IllegalArgumentException: wrong number of arguments #960

ber4444 opened this issue Oct 25, 2019 · 21 comments

Comments

@ber4444
Copy link

ber4444 commented Oct 25, 2019

In generated code

@JsonClass(generateAdapter = true)
data class Dashboard(
        val tabTitle1: String? = null,
)

becomes

    @Suppress("UNCHECKED_CAST")
    val localConstructor: Constructor<Dashboard> = this.constructorRef
        ?: Util.lookupDefaultsConstructor(Dashboard::class.java).also { this.constructorRef = it }
    return localConstructor.newInstance(
        tabTitle1,
        mask,
        null
    )
  }

in the latest snapshot, resulting in "java.lang.IllegalArgumentException: wrong number of arguments" for localConstructor.newInstance

why "mask" and "null" are added?

@ZacSweers
Copy link
Collaborator

Can you share the full stacktrace? This is moshi’s new mechanism for dynamically invoking the synthetic defaults constructor that kotlin generates.

@ber4444
Copy link
Author

ber4444 commented Oct 29, 2019


java.lang.NoSuchMethodError: com.squareup.moshi.internal.Util.lookupDefaultsConstructor(Ljava/lang/Class;)Ljava/lang/reflect/Constructor;

	at com.blah.blah.wctfeature.wctdashboard.viewmodel.model.DashboardJsonAdapter.fromJson(DashboardJsonAdapter.kt:365)
	at com.blah.blah.wctfeature.wctdashboard.viewmodel.model.DashboardJsonAdapter.fromJson(DashboardJsonAdapter.kt:17)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:137)
	at com.blah.blah.wctfeature.wctdashboard.viewmodel.model.StaticContentDataJsonAdapter.fromJson(StaticContentDataJsonAdapter.kt:147)
	at com.blah.blah.wctfeature.wctdashboard.viewmodel.model.StaticContentDataJsonAdapter.fromJson(StaticContentDataJsonAdapter.kt:17)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:137)
	at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:41)
	at com.blah.blah.wctfeature.custom.AddVendorListDialogTest.staticData_TestMethod(AddVendorListDialogTest.kt:18)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.mockito.internal.runners.DefaultInternalRunner$1$1.evaluate(DefaultInternalRunner.java:44)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:74)
	at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:80)
	at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
	at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


@ber4444
Copy link
Author

ber4444 commented Oct 29, 2019

It seems like the error changed in the snapshot from java.lang.IllegalArgumentException to java.lang.NoSuchMethodError

@ZacSweers
Copy link
Collaborator

does it work without mockito or in an otherwise reproducible test we could debug? Unfortunately the stacktrace and sample snippet alone doesn’t yield enough info to diagnose at a distance

@ZacSweers
Copy link
Collaborator

Actually - is you generated code compiled against an older snapshot? That would do it

@trevjonez
Copy link
Contributor

seeing the same in my project after updating to 1.9.0 today. it ends up being:
java.lang.IllegalArgumentException: Wrong number of arguments; expected 50, got 49 data class has 47 params. perhaps because we need an additional mask param each time you cross a 32 interval boundary?

@ZacSweers
Copy link
Collaborator

ZacSweers commented Oct 30, 2019

perhaps because we need an additional mask param each time you cross a 32 interval boundary

If you look at your class's decompiled bytecode, does that constructor have two masks? My understanding was that Kotlin basically could not accept more than 32 default parameters

@ZacSweers
Copy link
Collaborator

I'm 99% sure two masks isn't a thing and it's a hard limit. The logic we use is almost identical to what kotlin-reflect does, unless it also doesn't work for this case

@trevjonez
Copy link
Contributor

does that constructor have two masks?

indeed it does.
image
image

@ZacSweers
Copy link
Collaborator

wowow. Mind opening a separate issue to track that? That seems distinctly different from this one, and a limitation we'll need to figure out

@ZacSweers
Copy link
Collaborator

For now I'm going to close this one because I'm fairly certain it was a mismatch of runtime code and generated code. The method it's failing to find isn't the constructor, but rather the Util helper for doing it

@ber4444
Copy link
Author

ber4444 commented Oct 30, 2019

I upgraded to 1.9.0 and now I see the original error I reported. Here is the stack trace:

java.lang.IllegalArgumentException: wrong number of arguments

	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.blah.blah.wctfeature.wctdashboard.viewmodel.model.DashboardJsonAdapter.fromJson(DashboardJsonAdapter.kt:366)
	at com.blah.blah.wctfeature.wctdashboard.viewmodel.model.DashboardJsonAdapter.fromJson(DashboardJsonAdapter.kt:17)
	at com.squareup.moshi.internal.NullSafeJsonAdapter.fromJson(NullSafeJsonAdapter.java:40)
	at com.blah.blah.wctfeature.wctdashboard.viewmodel.model.StaticContentDataJsonAdapter.fromJson(StaticContentDataJsonAdapter.kt:147)
	at com.blah.blah.wctfeature.wctdashboard.viewmodel.model.StaticContentDataJsonAdapter.fromJson(StaticContentDataJsonAdapter.kt:17)
	at com.squareup.moshi.internal.NullSafeJsonAdapter.fromJson(NullSafeJsonAdapter.java:40)
	at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:43)
	at com.blah.blah.wctfeature.custom.AddVendorListDialogTest.staticData_TestMethod(AddVendorListDialogTest.kt:18)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.mockito.internal.runners.DefaultInternalRunner$1$1.evaluate(DefaultInternalRunner.java:44)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:74)
	at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:80)
	at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
	at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

@ZacSweers
Copy link
Collaborator

can you share a reproducible code snippet? Are you sure your models are being generated with the same version of moshi considering the original trace?

@ber4444
Copy link
Author

ber4444 commented Oct 30, 2019

Is there an email I can share the failing unit test to privately?

@ZacSweers
Copy link
Collaborator

ZacSweers commented Oct 30, 2019 via email

@ber4444
Copy link
Author

ber4444 commented Oct 30, 2019

done, let me know if you figure it out

@ZacSweers
Copy link
Collaborator

ZacSweers commented Oct 30, 2019 via email

@ber4444
Copy link
Author

ber4444 commented Oct 30, 2019

I send it again just now, maybe the zip attachment got blocked. Now it's a Google Drive link.

@ZacSweers
Copy link
Collaborator

ZacSweers commented Oct 30, 2019 via email

@ZacSweers
Copy link
Collaborator

Thanks for the test case @ber4444. I believe the new issue is the same as #977 and different than the original one posted here. #977 is fixed on master, your test case (at least with an empty json blob) works for me locally. Please try a master snapshot and see if that works for you locally to confirm?

@ber4444
Copy link
Author

ber4444 commented Oct 31, 2019

Thanks, the latest snapshot does work, so I guess you are right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants