Project

General

Profile

Bug #10978

Conversion NPE when creating a temp-table with LIKE that uses a different primary index

Added by Dănuț Filimon 8 months ago. Updated 4 months ago.

Status:
Test
Priority:
Normal
Assignee:
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
production:
No
env_name:
topics:

Related issues

Related to Database - Bug #10956: Wrong primary index selection on FOR EACH table Closed

History

#1 Updated by Dănuț Filimon 8 months ago

Test case:

define temp-table tt1 no-undo
   field f1            as character
   field f2          as date
   index idx1 is unique primary  f1
   index idx2             f2 desc.

define temp-table tt2 no-undo
   like tt1 
   use-index idx2 as primary.

Error:

     [java] com.goldencode.ast.AstException: Error processing ./abl/startt1.p
     [java]     at com.goldencode.p2j.uast.AstGenerator.processFile(AstGenerator.java:1080)
     [java]     at com.goldencode.p2j.uast.ScanDriver.lambda$scan$0(ScanDriver.java:469)
     [java]     at com.goldencode.p2j.uast.ScanDriver.scan(ScanDriver.java:509)
     [java]     at com.goldencode.p2j.uast.ScanDriver.scan(ScanDriver.java:318)
     [java]     at com.goldencode.p2j.convert.TransformDriver.runScanDriver(TransformDriver.java:432)
     [java]     at com.goldencode.p2j.convert.TransformDriver.front(TransformDriver.java:293)
     [java]     at com.goldencode.p2j.convert.TransformDriver.executeJob(TransformDriver.java:1082)
     [java]     at com.goldencode.p2j.convert.ConversionDriver.main(ConversionDriver.java:1258)
     [java] Caused by: java.lang.NullPointerException: Cannot invoke "com.goldencode.ast.Aast.addChild(antlr.collections.AST)" because "copyProps" is null
     [java]     at com.goldencode.p2j.schema.SchemaDictionary.copyIndex(SchemaDictionary.java:1809)
     [java]     at com.goldencode.p2j.uast.SymbolResolver.addIndexFrom(SymbolResolver.java:8289)
     [java]     at com.goldencode.p2j.uast.ProgressParser.temp_table_use_index(ProgressParser.java:52309)
     [java]     at com.goldencode.p2j.uast.ProgressParser.like_clause(ProgressParser.java:24828)
     [java]     at com.goldencode.p2j.uast.ProgressParser.def_temp_table_stmt(ProgressParser.java:15190)
     [java]     at com.goldencode.p2j.uast.ProgressParser.define_stmt(ProgressParser.java:14011)
     [java]     at com.goldencode.p2j.uast.ProgressParser.stmt_list(ProgressParser.java:27667)
     [java]     at com.goldencode.p2j.uast.ProgressParser.statement(ProgressParser.java:9964)
     [java]     at com.goldencode.p2j.uast.ProgressParser.single_block(ProgressParser.java:8520)
     [java]     at com.goldencode.p2j.uast.ProgressParser.block(ProgressParser.java:7609)
     [java]     at com.goldencode.p2j.uast.ProgressParser.external_proc(ProgressParser.java:7536)
     [java]     at com.goldencode.p2j.uast.AstGenerator.parse(AstGenerator.java:1658)
     [java]     at com.goldencode.p2j.uast.AstGenerator.processFile(AstGenerator.java:1068)
     [java]     ... 7 more

I've come up with a temporary patch in #10247-141.

#3 Updated by Constantin Asofiei 8 months ago

  • Related to Bug #10956: Wrong primary index selection on FOR EACH table added

#4 Updated by Constantin Asofiei 8 months ago

Teodor, please take a look.

#5 Updated by Teodor Gorghe 8 months ago

Ok

#6 Updated by Teodor Gorghe 8 months ago

I have tested with multiple cases with #10956 and this patch.
I have noticed that the change from #10247-141 are not right because the index should be primary.
This NPE happens when USE-INDEX is used on an index which does not have any property node (is not unique or primary).

The solution for this case is to create the property node if it does not exist:

=== modified file 'src/com/goldencode/p2j/schema/SchemaDictionary.java'
--- old/src/com/goldencode/p2j/schema/SchemaDictionary.java    2025-10-17 05:20:23 +0000
+++ new/src/com/goldencode/p2j/schema/SchemaDictionary.java    2025-11-14 12:13:38 +0000
@@ -1806,6 +1806,13 @@
             copyPrimary.setType(KW_PRIMARY);
             copyPrimary.setText("primary");
             copyPrimary.setParent(copyProps);
+
+            // If the source index doesn't have the property node, create it
+            if (copyProps == null)
+            {
+               copyProps = new ProgressAst();
+               copy.addChild(copyProps);
+            }
             copyProps.addChild(copyPrimary);
          }
       }

#7 Updated by Dănuț Filimon 6 months ago

Hi Teodor, is this part of the #10956 now?

#8 Updated by Teodor Gorghe 6 months ago

No, but if you want I can include there or in a separate branch.

#9 Updated by Dănuț Filimon 6 months ago

  • Status changed from New to WIP
  • Assignee set to Teodor Gorghe

Teodor Gorghe wrote:

No, but if you want I can include there or in a separate branch.

Please create a branch for this task and commit the patch from #10978-6. Let's get this reviewed and tested.

#10 Updated by Teodor Gorghe 6 months ago

  • vendor_id deleted (GCD)

Created task branch 10978a.

#11 Updated by Teodor Gorghe 6 months ago

  • Status changed from WIP to Review
  • vendor_id set to GCD
  • % Done changed from 0 to 100
  • reviewer Dănuț Filimon added

Committed revision 16348 on task branch 10978a:
- Fix for NPE when using USE-INDEX with no properties.

#12 Updated by Dănuț Filimon 6 months ago

Review 10978a/16348. The if statement should be before

copyPrimary.setParent(copyProps);
.

#13 Updated by Teodor Gorghe 6 months ago

Committed revision 16349 on task branch 10978a:
- Addressed code review #10978-12.

#14 Updated by Dănuț Filimon 6 months ago

  • Status changed from Review to Internal Test

Code review 10978a/16349. Looks good, let's move on to testing.

#15 Updated by Teodor Gorghe 4 months ago

Regression testing has passed.

#16 Updated by Teodor Gorghe 4 months ago

Danut, I think you would need to convert the application with trunk in the near future.
This is a reminder that this task can be merged to trunk, since all the testing was done and no regression spotted.

#17 Updated by Dănuț Filimon 4 months ago

Teodor Gorghe wrote:

Danut, I think you would need to convert the application with trunk in the near future.
This is a reminder that this task can be merged to trunk, since all the testing was done and no regression spotted.

I think trunk is frozen for delivery, I will let you know when you can merge the branch.

#18 Updated by Dănuț Filimon 4 months ago

  • Status changed from Internal Test to Merge Pending

Please merge to trunk now.

#19 Updated by Teodor Gorghe 4 months ago

  • Status changed from Merge Pending to Test

Branch 10978a was merged into trunk as rev. 16482 and archived.

Also available in: Atom PDF