web3j icon indicating copy to clipboard operation
web3j copied to clipboard

Exception thrown by SolidityFunctionWrapper when "double" as function name

Open didier-durand opened this issue 8 years ago • 5 comments

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)

didier-durand avatar Aug 03 '18 07:08 didier-durand

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

MykolaMarkov avatar Aug 03 '18 20:08 MykolaMarkov

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

didier-durand avatar Aug 04 '18 07:08 didier-durand

@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...

iikirilov avatar Nov 07 '18 10:11 iikirilov

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)

AriesChain-Dev avatar Feb 26 '19 09:02 AriesChain-Dev

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.

iikirilov avatar Mar 07 '19 14:03 iikirilov