Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Existence of mains in a class with a parameterful constructor leads to cbt fail #585

Open
buzden opened this issue Jan 26, 2018 · 1 comment

Comments

@buzden
Copy link
Contributor

buzden commented Jan 26, 2018

Consider I have (accidentially or not) some class X which has def main(args: Array[String]): Unit. CBT considers this as one of the variants of possible entry points during cbt run unless the class is abstract.

This behaviour is not fatal but a little bit annoying when you accidentially have written class instead of object and everything works fine with cbt but does not work with other tools (e.g. running with pure scala runner). In the code it's written that it's done because of dottydoc.

The really strange behaviour of cbt is when you have a really strange class having both constructor parameters and def main, something like this:

class X(whatever: Int) {
  def main(args: Array[String]): Unit = ???
}

Having this leads to (guess what):

Exception in thread "main" java.lang.InstantiationException: X
        at java.lang.Class.newInstance(Class.java:427)
        at cbt.reflect.Module$class.typeStaticMethod(reflect.scala:168)
        ...
Caused by: java.lang.NoSuchMethodException: X.<init>()
        ...

So, generally, cbt's reflection sublibrary assumes that it works with classes having a constructor with empty parameters list when talking about static methods (typeStaticMethod(Method) function).

@buzden buzden changed the title Mains of not only objects are considered to be entrypoints Existence of mains in a class with a parameterful constructor leads to cbt fail Jan 26, 2018
@cvogt
Copy link
Owner

cvogt commented Feb 12, 2018

fix in #587, let's keep this open to still add a test as described there. Probably by copying cbt/test/simple, adding the suggested classes and calling something like .mainMethods on the build and check it doesn't throw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants