| Summary: | Java calling ExternalType constructor that doesn't exist | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Kathy Carroll <carrollk> |
| Component: | EDT | Assignee: | Project Inbox <edt.compiler-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P1 | CC: | jeffdouglas, mheitz, pharmon, svihovec, tww |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
Amazingly, this is working as designed. It's a result of the nullability language changes that were made recently.
There's no question mark on this declaration:
outWriter FileWriter;
so that means the variable is not nullable. That means it's never supposed to be null, so we have to call a constructor to create a FileWriter object. It's as if, before the nullability change, you had written this instead:
outWriter FileWriter {};
You can either add the question mark:
outWriter FileWriter?;
or declare it on the same line where you give it a value:
try
outWriter FileWriter = new FileWriter(fullFileName);
Should I be getting a validation error message since the constructor that will be used isn't defined in the ExternalType? A validation check will be added to ensure that things which can't be instantiated (interfaces & things with private default constructors) must be declared nullable. Constructors can be in ETs and (soon) handlers. Tim, please answer Kathy's question. (The second paragraph in her comment is from my writeup of the enhancement.) It seems to me that either her ET needs a private default constructor, or we should add "types without a default constructor" to the list of things that can't be instantiated. Need an answer the question specified in Comment 2 & 3 It seems to me after reading this, that this is a validation defect, not javagen. I asked Tim about this a few weeks ago. He said (basically) that unless they have defined a private default constructor, that we should assume that the type is instantiable. I believe that is because it is just Java's implementation that says that if a class has a non-default constructor that it does not have an implicit default constructor. Other languages may not have that same rule. If you define a private default constructor in the externaltype, you will get a validation error. Because of this, I am marking this as WontFix ok |
=========== EGL code ================ handler CreateResultsFile function createFile(fileDirectory String in, fullFileName String in, fileContent String in) myfile File = new File(fileDirectory); createdDirs boolean = myfile.mkdirs(); if(createdDirs) SysLib.writeStdOut("directories created"); end outWriter FileWriter; try outWriter = new FileWriter(fullFileName); outWriter.write(fileContent); outWriter.close_(); onException (exp AnyException) end end end ExternalType File type JavaObject {packageName = "java.io"} constructor (pathname String In); function getAbsolutePath() returns (String); function createNewFile() returns (boolean); function mkdirs() returns (boolean); function exists() returns (boolean); end ExternalType FileWriter type JavaObject { packageName = "java.io"} constructor (file File In); constructor (filename String In); function write(str String In); function close_() {externalName ="close"}; end ================= Java Code ============= FileWriter outWriter = null; outWriter = new FileWriter(); try { outWriter = new FileWriter(fullFileName); outWriter.write(fileContent); outWriter.close(); }