avishek-sen-gupta / cobol-rekt

An evolving toolkit of capabilities helpful for reverse engineering legacy Cobol code
MIT License
92 stars 10 forks source link

Issue: NoSuchElementException #59

Open acurat opened 3 weeks ago

acurat commented 3 weeks ago

Ran into this error trying to summarize a program. Please let me know if you need any other info.


[2024-11-06 14:17:23] [FINER] Setting value for 01WS-END-LITERALPICX(29)VALUE'END WORKING STORAGE - OLWS810'. 
[2024-11-06 14:17:23] [FINER] Setting value for 01DFHCOMMAREAPICX(99999). 
java.util.NoSuchElementException
    at java.base/java.util.List.getFirst(List.java:825)
    at org.smojol.common.vm.structure.Format1DataStructure.typeSpecForSingle(Format1DataStructure.java:207)
    at org.smojol.common.vm.structure.Format1DataStructure.calculateMemoryRequirements(Format1DataStructure.java:200)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at org.smojol.common.vm.structure.Format1DataStructure.typeSpecForSingle(Format1DataStructure.java:209)
    at org.smojol.common.vm.structure.Format1DataStructure.calculateMemoryRequirements(Format1DataStructure.java:200)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at org.smojol.common.vm.structure.Format1DataStructure.typeSpecForSingle(Format1DataStructure.java:209)
    at org.smojol.common.vm.structure.Format1DataStructure.calculateMemoryRequirements(Format1DataStructure.java:200)
    at org.smojol.common.structure.CobolDataStructureBuilder.build(CobolDataStructureBuilder.java:41)
    at org.smojol.toolkit.analysis.validation.DataStructureValidation$1.run(DataStructureValidation.java:31)
    at org.smojol.toolkit.analysis.pipeline.ParsePipeline.parse(ParsePipeline.java:155)
    at org.smojol.toolkit.analysis.pipeline.ParsePipeline.parse(ParsePipeline.java:81)
    at org.smojol.toolkit.analysis.task.analysis.BuildSeedModelTask.run(BuildSeedModelTask.java:30)
    at org.smojol.toolkit.task.SmojolTasks$15.run(SmojolTasks.java:169)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:722)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575)
    at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260)
    at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616)
    at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:622)
    at java.base/java.util.stream.ReferencePipeline.toList(ReferencePipeline.java:627)
    at org.smojol.toolkit.task.SmojolTasks.run(SmojolTasks.java:64)
    at org.smojol.toolkit.analysis.task.analysis.CodeTaskRunner.runForProgram(CodeTaskRunner.java:154)
    at org.smojol.toolkit.analysis.task.analysis.CodeTaskRunner.runForPrograms(CodeTaskRunner.java:95)
    at org.smojol.cli.MultiCommand.processPrograms(MultiCommand.java:105)
    at org.smojol.cli.MultiCommand.call(MultiCommand.java:92)
    at org.smojol.cli.MultiCommand.call(MultiCommand.java:30)
    at picocli.CommandLine.executeUserObject(CommandLine.java:2041)
    at picocli.CommandLine.access$1500(CommandLine.java:148)
    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
    at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
    at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
    at picocli.CommandLine.execute(CommandLine.java:2170)
    at org.smojol.cli.MultiCommandCLI.main(MultiCommandCLI.java:10)
[2024-11-06 14:17:23] [FINE] Runtime.exit() called with status: 1 ```
avishek-sen-gupta commented 3 weeks ago

could you paste the space-separated version of the line 01DFHCOMMAREAPICX(99999) here?

acurat commented 3 weeks ago

Pasting that part of the code...

       LINKAGE SECTION.

       01  DFHCOMMAREA              PIC X(99999).

       PROCEDURE DIVISION USING DFHCOMMAREA.

       0000-MAINLINE.

           STRING WS-THIS-PROGRAM
                   '0000-MAINLINE'
           DELIMITED BY SIZE INTO TDQMSG
           PERFORM 9988-CSMT-LOG
avishek-sen-gupta commented 3 weeks ago

I'm unable to reproduce this issue from this code fragment. Could I ask you to do two things?

acurat commented 2 weeks ago

The logs now print

[2024-11-08 23:55:39] [FINER] Setting value for 01DFHCOMMAREAPICX(99999). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-BCKT-ORD-TIMEPICX(26). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-AREA-IPICS9(9)USAGECOMP. 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-AREA-JPICS9(9)USAGECOMP. 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-DATE-LOAD-ERLYPICX(10). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-DATE-LOAD-LATEPICX(10). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-MILE-TOTPICS9(5)VUSAGECOMP-3. 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-FEET-CUBE-TOTPICS9(5)VUSAGECOMP-3. 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-WGHT-TOTPICS9(7)VUSAGECOMP-3. 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-CNT-ORD-TOTPICS9(3)VUSAGECOMP-3. 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-NBR-AGT-OWNR-VANPICS9(5)VUSAGECOMP-3. 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-CODE-SUB-OWNR-VANPICX(1). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-NBR-VANPICX(7). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-CODE-SUB-CMPY-VANPICX(1). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-CODE-STAT-LOADPICX(1). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-INDT-VIEW-AGTPICX(1). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-IDEN-LOADPICX(8). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-NAME-BEGN-CITYPICX(20). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-CODE-BEGN-STPICX(2). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-NAME-END-CITYPICX(20). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-CODE-END-STPICX(2). 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-AMT-REV-TOTPICS9(7)V9(2)USAGECOMP-3. 
[2024-11-08 23:55:39] [INFO] Calculating type spec for single data structure: 10LOADBUCKET-LAT-BEGNUSAGECOMP-1. 
java.util.NoSuchElementException
    at java.base/java.util.List.getFirst(List.java:825)
    at org.smojol.common.vm.structure.Format1DataStructure.typeSpecForSingle(Format1DataStructure.java:208)
    at org.smojol.common.vm.structure.Format1DataStructure.calculateMemoryRequirements(Format1DataStructure.java:200)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at org.smojol.common.vm.structure.Format1DataStructure.typeSpecForSingle(Format1DataStructure.java:210)
    at org.smojol.common.vm.structure.Format1DataStructure.calculateMemoryRequirements(Format1DataStructure.java:200)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

The program includes this in the working storage section

           EXEC SQL
              INCLUDE LOADBUCK
           END-EXEC.    

And this is the relevant part in LOADBUCK

      *                       AMT_REV_TOT
           10 LOADBUCKET-AMT-REV-TOT
              PIC S9(7)V9(2) USAGE COMP-3.
      *                       LAT_BEGN
           10 LOADBUCKET-LAT-BEGN  USAGE COMP-1.
      *                       LAT_END
           10 LOADBUCKET-LAT-END   USAGE COMP-1.
      *                       LONG_BEGN
           10 LOADBUCKET-LONG-BEGN
              USAGE COMP-1.
      *                       LONG_END
           10 LOADBUCKET-LONG-END  USAGE COMP-1.

Hope that gives you enough info.

avishek-sen-gupta commented 2 weeks ago

Thanks, that helps. The library currently does not recognise COMP-1 records. I have opened issue #64 to track and work on this. I'll keep this issue open till then.

avishek-sen-gupta commented 2 weeks ago

This should be fixed in commit 00a0f8bb495ce0dee67c5260a42a9fb22cbc0963. Could you check?