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

Exception thrown by SolidityFunctionWrapper when "double" as function name #658

Closed
didier-durand opened this issue Aug 3, 2018 · 5 comments
Labels
fixed-awaiting-pr-approval issue is fixed, PR that needs-approval

Comments

@didier-durand
Copy link

Hi,

"double" as function name makes class SolidityFunctionWrapper throw an exception. See stack trace below.

Solidity code to reproduce:

pragma solidity ^0.4.24;

contract TestEthCall {
function double(int a) pure public returns(int) {
return 2*a;
}
}

Best,
Didier

java.lang.IllegalArgumentException: not a valid name: double
at com.squareup.javapoet.Util.checkArgument(Util.java:64)
at com.squareup.javapoet.MethodSpec$Builder.(MethodSpec.java:296)
at com.squareup.javapoet.MethodSpec$Builder.(MethodSpec.java:281)
at com.squareup.javapoet.MethodSpec.methodBuilder(MethodSpec.java:175)
at org.web3j.codegen.SolidityFunctionWrapper.buildFunction(SolidityFunctionWrapper.java:591)
at org.web3j.codegen.SolidityFunctionWrapper.buildFunctionDefinitions(SolidityFunctionWrapper.java:251)
at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:130)
at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:111)
at org.web3j.codegen.SolidityFunctionWrapperGenerator.generate(SolidityFunctionWrapperGenerator.java:123)
at org.web3j.codegen.SolidityFunctionWrapperGenerator.main(SolidityFunctionWrapperGenerator.java:87)
at io.recognichain.core.SolidityCompiler.generateJavaWrapper(SolidityCompiler.java:45)
at io.recognichain.test.TestEthCall.compileEthCall(TestEthCall.java:23)
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.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.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:83)
at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:74)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

@MykolaMarkov
Copy link

double is reserved word it can't be used as function or variable name.

@didier-durand
Copy link
Author

Yes, I know that double is a reserved word. But, it's reserved in Java: the Solidity code that I submitted to reproduce is compiled without any problem by Solidity compiler.

Why should we introduce a Java restriction into Solidity contracts? programmers of smart contracts can't take into account the limitations of all languages dealing in some form with their Solidity programs.

I would suggest to prefix the name of a function by underscore (or anything else) when the function name is a Java reserved word. That would be the burden on Java side for a proper call, not on Solidity side.

(Additiionally, for somebody collecting existing ABIs from existing contracts on the Ethereum, no chance to contact the programmer to ask him to change the name of his function)
Best
Didier

@iikirilov
Copy link
Contributor

iikirilov commented Nov 7, 2018

@conor10 thoughts on this? I think prefix with an underscore is sensible in this case.

It could also be suffix with an underscore to preserve the ordering of methods when using intellij...

@CoinInn-Aries
Copy link

Generating com.gomo.ethchain.contract.FountainTokenUpgrade ... Exception in thread "main" java.lang.IllegalArgumentException: not a valid name:
at com.squareup.javapoet.Util.checkArgument(Util.java:64)
at com.squareup.javapoet.FieldSpec.builder(FieldSpec.java:92)
at com.squareup.javapoet.TypeSpec$Builder.addField(TypeSpec.java:499)
at org.web3j.codegen.SolidityFunctionWrapper.buildEventResponseObject(SolidityFunctionWrapper.java:854)
at org.web3j.codegen.SolidityFunctionWrapper.buildEventFunctions(SolidityFunctionWrapper.java:999)
at org.web3j.codegen.SolidityFunctionWrapper.buildFunctionDefinitions(SolidityFunctionWrapper.java:266)
at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:137)
at org.web3j.codegen.TruffleJsonFunctionWrapperGenerator.generate(TruffleJsonFunctionWrapperGenerator.java:134)
at org.web3j.codegen.TruffleJsonFunctionWrapperGenerator.main(TruffleJsonFunctionWrapperGenerator.java:98)
at org.web3j.codegen.TruffleJsonFunctionWrapperGenerator.run(TruffleJsonFunctionWrapperGenerator.java:62)
at org.web3j.console.Runner.main(Runner.java:42)

@iikirilov
Copy link
Contributor

Closing as this issue was fixed by #766

@sywuestc please open a new issue if there is still a bug. It will be useful to have a failing contract so I can replicate and fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-awaiting-pr-approval issue is fixed, PR that needs-approval
Projects
None yet
Development

No branches or pull requests

4 participants