:gen-class possibly missing a compile time check when extending abstract classes that implement interfaces
I ran into this when creating a log4j appender in Clojure. I extended the AppenderSkeleton, an abstract class. This abstract class implements Appender. Appender defines two methods that don't appear in the AbstractSkeleton (requiresLayout & close). I was able to compile the Clojure class, without the two methods in question, with no error. I then threw a runtime exception when I tried to use the class. The fix was easy but it seems this should probably be checked at compile time. Clojure 1.2.1 Log4j 1.2.15 -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: :gen-class possibly missing a compile time check when extending abstract classes that implement interfaces
I also ran into this recently - doing the exact same thing (a log4j appender). I was a bit surprised and I wonder if Clojure is effectively generating abstract classes rather than concrete classes? (Do we have no way to specify the difference? Is that only an artifact of the Java compiler, not the JVM bytecode?) As you say, the fix tends to be easy (read the class API docs and implement the missing methods) but the behavior needs to be clearly documented (on clojure.org) to help people avoid the problem I think... Sean On Sun, May 29, 2011 at 7:04 AM, ckirkendall wrote: > I ran into this when creating a log4j appender in Clojure. I extended > the AppenderSkeleton, an abstract class. This abstract class > implements Appender. Appender defines two methods that don't appear > in the AbstractSkeleton (requiresLayout & close). I was able to > compile the Clojure class, without the two methods in question, with > no error. I then threw a runtime exception when I tried to use the > class. The fix was easy but it seems this should probably be checked > at compile time. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: :gen-class possibly missing a compile time check when extending abstract classes that implement interfaces
I added an explanation of this a comment to the documentation on http://clojuredocs.org On May 29, 3:01 pm, Sean Corfield wrote: > I also ran into this recently - doing the exact same thing (a log4j > appender). I was a bit surprised and I wonder if Clojure is > effectively generating abstract classes rather than concrete classes? > (Do we have no way to specify the difference? Is that only an artifact > of the Java compiler, not the JVM bytecode?) > > As you say, the fix tends to be easy (read the class API docs and > implement the missing methods) but the behavior needs to be clearly > documented (on clojure.org) to help people avoid the problem I > think... > > Sean > > > > On Sun, May 29, 2011 at 7:04 AM, ckirkendall wrote: > > I ran into this when creating a log4j appender in Clojure. I extended > > the AppenderSkeleton, an abstract class. This abstract class > > implements Appender. Appender defines two methods that don't appear > > in the AbstractSkeleton (requiresLayout & close). I was able to > > compile the Clojure class, without the two methods in question, with > > no error. I then threw a runtime exception when I tried to use the > > class. The fix was easy but it seems this should probably be checked > > at compile time. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: :gen-class possibly missing a compile time check when extending abstract classes that implement interfaces
> I was a bit surprised and I wonder if Clojure is > effectively generating abstract classes rather than concrete classes? > (Do we have no way to specify the difference? Is that only an artifact > of the Java compiler, not the JVM bytecode?) I don't think Clojure will generate abstract classes; the compiler would have to set it up as abstract with non-implemented methods as abstract, too (it goes to the bytecode). My guess is you're getting a verify error wit an incomplete class. In these cases it'd be helpful to get automatically generated stubs that throw a not implemented exception, like with proxies. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Aw: :gen-class possibly missing a compile time check when extending abstract classes that implement interfaces
Hi, I think, clojure just generates a class with stubs for all methods, which check whether an implementing function exists. If yes, they call it. If no, they pass on to super. If there is no such method in super, they throw a reasonable exception. Eg. I get the following for a class implementing Iterable without defining -iterator: UnsupportedOperationException iterator (foo.Bar/-iterator not defined?) foo.Bar.iterator (:-1) What might be a problem though, is that your superclass claims to implement a given interface without actually doing so. Then clojure sees the "implemented" methods, but calling them will fail. My gut feeling is, that the abstract class should document, that you have to implement these methods. Having javac point you to such a fact is not good-style, IMHO. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: :gen-class possibly missing a compile time check when extending abstract classes that implement interfaces
I disagree currently this is a compile time checks provided by javac. On May 30, 11:42 am, Meikel Brandmeyer wrote: > Hi, > > I think, clojure just generates a class with stubs for all methods, which > check whether an implementing function exists. If yes, they call it. If no, > they pass on to super. If there is no such method in super, they throw a > reasonable exception. Eg. I get the following for a class implementing > Iterable without defining -iterator: > UnsupportedOperationException iterator (foo.Bar/-iterator not defined?) > foo.Bar.iterator (:-1) > > What might be a problem though, is that your superclass claims to implement > a given interface without actually doing so. Then clojure sees the > "implemented" methods, but calling them will fail. > > My gut feeling is, that the abstract class should document, that you have to > implement these methods. Having javac point you to such a fact is not > good-style, IMHO. > > Sincerely > Meikel -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en