Bug #4154
NPE in ENABLE ALL
100%
History
#1 Updated by Vladimir Tsichevski almost 5 years ago
The problem¶
For the following 4gl code conversion throws NullPointerException
:
FORM sometable WITH FRAME f. ENABLE ALL WITH FRAME f.
where sometable
is a database (not temporary) table with at least one field.
Environment¶
bzr revno 11327
How to reproduce¶
- go to testcases:
pushd ~/testcases/uast
- make a symbolic link to the directory with a build p2j project under test:
ln -s <p2j-branch-to-test> p2j
- create a file named
4154.p
with the following contents:
FORM Book WITH FRAME f. ENABLE ALL WITH FRAME f.
here Book
is the name of a table in the @p2j_test* database.
- edit the
file-cvt-list.txt
, put the4154.p
into it; - run
P2J_HOME=p2j ant convert-all jar -D4gl.file.list=file-cvt-list.txt
or just
java -classpath p2j/build/lib/p2j.jar com.goldencode.p2j.convert.ConversionDriver f0 4154.p
You should see these warning and error messages in the program output:
------------------------------------------------------------------------------ Scanning Progress Source (lexer, parser, persist ASTs) ------------------------------------------------------------------------------ abl/bad.p WARNING: Null annotation (name) for p2j_test.book.publisher [FIELD_CHAR] @0:0 WARNING: Null annotation (name) for p2j_test.book.book-title [FIELD_CHAR] @0:0 WARNING: Null annotation (name) for p2j_test.book.book-id [FIELD_INT] @0:0 WARNING: Null annotation (name) for p2j_test.book.isbn [FIELD_CHAR] @0:0 WARNING: Null annotation (name) for p2j_test.book.sold-qty [FIELD_INT] @0:0 WARNING: Null annotation (name) for p2j_test.book.pub-date [FIELD_DATE] @0:0 WARNING: Null annotation (name) for p2j_test.book.author-id [FIELD_INT] @0:0 WARNING: Null annotation (name) for p2j_test.book.on-hand-qty [FIELD_INT] @0:0 WARNING: Null annotation (name) for p2j_test.book.price [FIELD_DEC] @0:0 WARNING: Null annotation (name) for p2j_test.book.cost [FIELD_DEC] @0:0 Failure in file '4154.p': com.goldencode.ast.AstException: Error processing ./abl/bad.p at com.goldencode.p2j.uast.AstGenerator.processFile(AstGenerator.java:972) at com.goldencode.p2j.uast.ScanDriver.lambda$scan$0(ScanDriver.java:375) at com.goldencode.p2j.uast.ScanDriver.scan(ScanDriver.java:410) at com.goldencode.p2j.uast.ScanDriver.scan(ScanDriver.java:248) at com.goldencode.p2j.convert.TransformDriver.runScanDriver(TransformDriver.java:352) at com.goldencode.p2j.convert.TransformDriver.front(TransformDriver.java:223) at com.goldencode.p2j.convert.TransformDriver.executeJob(TransformDriver.java:862) at com.goldencode.p2j.convert.ConversionDriver.main(ConversionDriver.java:983) Caused by: java.lang.NullPointerException: null value for annotation 'name':p2j_test.book.sold-qty [FIELD_INT]:12884901913 @0:0 HIDDEN at com.goldencode.ast.XmlFilePlugin.writeSingleAnnotation(XmlFilePlugin.java:1115) at com.goldencode.ast.XmlFilePlugin.writeAnnotations(XmlFilePlugin.java:1076) at com.goldencode.ast.XmlFilePlugin.writeAst(XmlFilePlugin.java:1035) at com.goldencode.ast.XmlFilePlugin.writeAst(XmlFilePlugin.java:1041) at com.goldencode.ast.XmlFilePlugin.writeAst(XmlFilePlugin.java:1041) at com.goldencode.ast.XmlFilePlugin.writeAst(XmlFilePlugin.java:1041) at com.goldencode.ast.XmlFilePlugin.writeAst(XmlFilePlugin.java:1041) at com.goldencode.ast.XmlFilePlugin.saveTree(XmlFilePlugin.java:487) at com.goldencode.ast.AstManager.saveTree(AstManager.java:322) at com.goldencode.p2j.uast.AstGenerator.persistAst(AstGenerator.java:1790) at com.goldencode.p2j.uast.AstGenerator.parse(AstGenerator.java:1543) at com.goldencode.p2j.uast.AstGenerator.processFile(AstGenerator.java:967) ... 7 more
#2 Updated by Vladimir Tsichevski almost 5 years ago
Analysis¶
The NPE arises while the resulting XML is generated. It is caused by a badly formed "note" annotation in the AST node: the annotation exists in the Map, but the value of the MapEntry is null.
I do not know why this situation is ever allowed in any program. Do such annotation exist by design?
The annotation is created by the following code (src/com/goldencode/p2j/uast/progress.g
, line 18453) in the enable_stmt()
:
wid.putAnnotation("name", (String) fld.getAnnotation("name"));
the fld
AST node has no annotation names "name", so the null
value is written to the annotation map.
The fld
value, in turn, is created in the form_stmt()
, which in turn, calls the record_spec()
to fill the field list, which creates an AST node with the "schemaname" and "bufname" annotations only:
Aast fldRef = new ProgressAst(); fldRef.setType(fld.getType()); fldRef.setText(bufname + "." + fname); fldRef.putAnnotation("schemaname", sname + "." + fname); fldRef.putAnnotation("bufname", bufname);
As we may see, the field, which is used in the enable_stmt()
in the fld
variable, has no "name" annotation.
Workaround¶
The wid
node in the problematic code, in this very situation at least, NEED NOT to be annotated with "name", since it was already annotated on creation:
So the line probably can be deleted:
wid.putAnnotation("name", (String) fld.getAnnotation("name"));
The question is why this line was ever added?
#3 Updated by Vladimir Tsichevski almost 4 years ago
Update: now (3821c rev. 11487) the stack trace looks a bit different:
[java] Optional rule set [customer_specific_annotations_prep] not found. [java] ./abl/bad.p [java] EXPRESSION EXECUTION ERROR: [java] --------------------------- [java] throwException(sprintf(spec, bufname, reftype), this) [java] ^ { Cannot find buffer named test3820.master_test3820.master for ref type 21! [FIELD_INT id <12884901914> 0:0] } [java] --------------------------- [java] Elapsed job time: 00:00:00.792 [java] ERROR: [java] com.goldencode.p2j.pattern.TreeWalkException: ERROR! Active Rule: [java] ----------------------- [java] RULE REPORT [java] ----------------------- [java] Rule Type : WALK [java] Source AST: [ master-id ] BLOCK/STATEMENT/KW_FORM/FORM_ITEM/FIELD_INT/ @0:0 {12884901914} [java] Copy AST : [ master-id ] BLOCK/STATEMENT/KW_FORM/FORM_ITEM/FIELD_INT/ @0:0 {12884901914} [java] Condition : throwException(sprintf(spec, bufname, reftype), this) [java] Loop : false [java] --- END RULE REPORT --- [java] [java] [java] [java] at com.goldencode.p2j.pattern.PatternEngine.run(PatternEngine.java:1070) [java] at com.goldencode.p2j.convert.TransformDriver.processTrees(TransformDriver.java:569) [java] at com.goldencode.p2j.convert.ConversionDriver.back(ConversionDriver.java:573) [java] at com.goldencode.p2j.convert.TransformDriver.executeJob(TransformDriver.java:956) [java] at com.goldencode.p2j.convert.ConversionDriver.main(ConversionDriver.java:1025) [java] Caused by: com.goldencode.expr.ExpressionException: Expression execution error @1:1 [FIELD_INT id=12884901914] [java] at com.goldencode.p2j.pattern.AstWalker.walk(AstWalker.java:275) [java] at com.goldencode.p2j.pattern.AstWalker.walk(AstWalker.java:210) [java] at com.goldencode.p2j.pattern.PatternEngine.apply(PatternEngine.java:1633) [java] at com.goldencode.p2j.pattern.PatternEngine.processAst(PatternEngine.java:1531) [java] at com.goldencode.p2j.pattern.PatternEngine.processAst(PatternEngine.java:1479) [java] at com.goldencode.p2j.pattern.PatternEngine.run(PatternEngine.java:1034) [java] ... 4 more [java] Caused by: com.goldencode.expr.ExpressionException: Expression execution error @1:1 [java] at com.goldencode.expr.Expression.execute(Expression.java:484) [java] at com.goldencode.p2j.pattern.Rule.apply(Rule.java:497) [java] at com.goldencode.p2j.pattern.Rule.executeActions(Rule.java:745) [java] at com.goldencode.p2j.pattern.Rule.coreProcessing(Rule.java:712) [java] at com.goldencode.p2j.pattern.Rule.apply(Rule.java:534) [java] at com.goldencode.p2j.pattern.Rule.executeActions(Rule.java:745) [java] at com.goldencode.p2j.pattern.Rule.coreProcessing(Rule.java:712) [java] at com.goldencode.p2j.pattern.Rule.apply(Rule.java:534) [java] at com.goldencode.p2j.pattern.Rule.executeActions(Rule.java:745) [java] at com.goldencode.p2j.pattern.Rule.coreProcessing(Rule.java:712) [java] at com.goldencode.p2j.pattern.Rule.apply(Rule.java:534) [java] at com.goldencode.p2j.pattern.Rule.executeActions(Rule.java:745) [java] at com.goldencode.p2j.pattern.Rule.coreProcessing(Rule.java:712) [java] at com.goldencode.p2j.pattern.Rule.apply(Rule.java:534) [java] at com.goldencode.p2j.pattern.RuleContainer.apply(RuleContainer.java:585) [java] at com.goldencode.p2j.pattern.RuleSet.apply(RuleSet.java:98) [java] at com.goldencode.p2j.pattern.AstWalker.walk(AstWalker.java:262) [java] ... 9 more [java] Caused by: com.goldencode.p2j.pattern.CommonAstSupport$UserGeneratedException: Cannot find buffer named test3820.master_test3820.master for ref type 21! [FIELD_INT id <12884901914> 0:0] [java] at com.goldencode.p2j.pattern.CommonAstSupport$Library.throwException(CommonAstSupport.java:2999) [java] at com.goldencode.expr.CE7060.execute(Unknown Source) [java] at com.goldencode.expr.Expression.execute(Expression.java:391) [java] ... 25 more
#4 Updated by Vladimir Tsichevski 10 months ago
- Status changed from New to WIP
#5 Updated by Vladimir Tsichevski 10 months ago
- Status changed from WIP to Review
- % Done changed from 0 to 100
Seems, the issue does not exist anymore. The 4gl code example converts with no issues. This issue can be closed/rejected.