bugKawa - Bugs: bug #48347, Exception on import of class with...

 
 

bug #48347: Exception on import of class with public instance fields and without no-args ctor

Submitter:  Nathan S. <nathans>
Submitted:  Wed 29 Jun 2016 08:01:35 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  Run-time exception Status:  Invalid
Privacy:  Public Assigned to:  bothner
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 29 Jun 2016 08:58:59 PM UTC, comment #1: 

The import form, when used in that variant, requires Example to be a "module class" or at least Kawa tries to view it as such, which it isn't, for various reasons, including that it doesn't have a default constructor.

Kawa import is not the same as Java import.  (import Example)
means "import the public names of (fields in) Example into the current scope".
For static fields there is no problem, but for instance fields it first tries to construct an instance.

This should be a compile-time error, I admit.

There is no need for the import if Example is in the default package: just use Example directory.

Otherwise read: http://www.gnu.org/software/kawa/FAQs.html
If Example is in package p, then you could do:
(import (class p Example))

More useful reading:
http://www.gnu.org/software/kawa/Module-classes.html
http://www.gnu.org/software/kawa/Importing.html

Per Bothner <bothner>
Group administrator
Wed 29 Jun 2016 08:01:35 PM UTC, original submission:  

Steps to reproduce:

Create a file Example.java with contents:

public class Example {
        public Object item;
        public Example(Object item) {
                this.item = item;
        }
}


Create a file test.scm with contents:


(import Example)

(display (Example:new #!null))


Run "javac Example.java".  Then with the current directory included on the classpath run "kawa -f test.scm".  An exception is thrown from gnu.expr.ModuleContext.findInstance because it attempts to invoke the no-args constructor of Example and there is not one.  It does not seem to matter if I put Example in a package other than the default package.

Strangely, if I change the visibility of Example's item field from public to private the error does not occur.

Nathan S. <nathans>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #37627:  Example.java added by nathans (102B - text/x-java)
file #37628:  test.scm added by nathans (49B - application/vnd.lotus-screencam)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bothner (Posted a comment)
  • -email is unavailable- added by nathans (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-07-28 bothner Open/ClosedOpen Closed
    2016-06-29 bothner StatusNone Invalid
        Assigned toNone bothner
    2016-06-29 nathans Attached File- Added Example.java, #37627
        Attached File- Added test.scm, #37628

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code