Bug #5557
Direct Java conversion: incorrect method call argument conversion
Start date:
Due date:
% Done:
100%
billable:
No
vendor_id:
GCD
case_num:
version:
History
#1 Updated by Vladimir Tsichevski almost 3 years ago
Example 4gl:
USING java.io.ByteArrayOutputStream FROM JAVA. DEFINE VARIABLE bos AS ByteArrayOutputStream. bos = new ByteArrayOutputStream(10000). USING java.io.DataOutputStream FROM JAVA. DEFINE VARIABLE out AS DataOutputStream. out = new DataOutputStream(bos).
Converts to Java as:
... @LegacySignature(type = Type.VARIABLE, name = "bos") jobject<? extends ByteArrayOutputStream> bos = UndoableFactory.jobject(ByteArrayOutputStream.class); @LegacySignature(type = Type.VARIABLE, name = "out") jobject<? extends DataOutputStream> out = UndoableFactory.jobject(DataOutputStream.class); @LegacySignature(type = Type.MAIN, name = "test-java.p") public void execute() { externalProcedure(TestJava.this, new Block((Init) () -> { ObjectOps.register(out, bos); }, (Body) () -> { bos.assign(new java.io.ByteArrayOutputStream(10000)); out.assign(new java.io.DataOutputStream(bos)); })); }
ByteArrayOutputStream
Note an object of type
jobject
is passed to new java.io.DataOutputStream(bos)
instead of a ByteArrayOutputStream
instance. The correct conversion output here must be new java.io.DataOutputStream(bos.ref())
.#3 Updated by Constantin Asofiei almost 3 years ago
Please try this patch:
### Eclipse Workspace Patch 1.0 #P p2j Index: rules/convert/variable_references.rules =================================================================== --- rules/convert/variable_references.rules (revision 2943) +++ rules/convert/variable_references.rules (working copy) @@ -901,6 +901,13 @@ <rule on="false">not(this.indexPos == 1 and parent.type == prog.object_invocation) <action>lastid = closestPeerId</action> + <!-- java variables need a 'ref' if passed as an argument to a Java-style call --> + <rule>parent.type == prog.parameter and + evalLib("is_java_cls", this) and + evalLib("is_java_cls", parent.parent.parent) + <action>lastid = createJavaAst(java.method_call, "ref", lastid)</action> + </rule> + <!-- emit variable/accessor --> <action>createPeerAst(methodType, methodTxt, lastid)</action>
#4 Updated by Vladimir Tsichevski almost 3 years ago
Constantin Asofiei wrote:
Please try this patch:
[...]
It works, thank you! Will you commit the patch?
#5 Updated by Constantin Asofiei almost 3 years ago
- Status changed from New to WIP
- % Done changed from 0 to 100
- Assignee set to Constantin Asofiei
Fixed in 3821c rev 12697.
#6 Updated by Vladimir Tsichevski almost 3 years ago
- Status changed from WIP to Review
#7 Updated by Greg Shah almost 3 years ago
- Status changed from Review to Closed