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

lein uberjar error. No matching ctor found for class io.pedestal.interceptor.helpers$before$fn #308

Closed
mavbozo opened this Issue Jan 29, 2015 · 10 comments

Comments

Projects
None yet
6 participants
@mavbozo
Contributor

mavbozo commented Jan 29, 2015

I want to create uberjar but the process fails and I get this error:

Caused by: java.lang.IllegalArgumentException: No matching ctor found for class io.pedestal.interceptor.helpers$before$fn__6182

Detailed explanation follows:

  • OS
    • Debian Wheezy
    • Windows 7
  • Leiningen 2.5.1 on Java 1.7.0_75 Java HotSpot(TM) 64-Bit Server VM
  • Pedestal Version 0.4.0-SNAPSHOT at 88b940c
  • Steps to reproduce:
    1. lein new pedestal-service ctor-errors
    2. edit project.clj to use 0.4.0-SNAPSHOT version
    3. add {:uberjar :aot :all} to :profiles
    4. add new handler using defbefore in service.clj
    5. lein uberjar

I created a repository to reproduce that problem https://github.com/mavbozo/ctor-errors

Here is the error stacktrace

mavbozo-> lein uberjar
Compiling ctor-errors.server
INFO  org.eclipse.jetty.util.log - Logging initialized @22705ms
Compiling ctor-errors.service
java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:274)
    at clojure.lang.RT.loadClassForName(RT.java:2093)
    at clojure.lang.RT.load(RT.java:430)
    at clojure.lang.RT.load(RT.java:411)
    at clojure.core$load$fn__5066.invoke(core.clj:5641)
    at clojure.core$load.doInvoke(core.clj:5640)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5446)
    at clojure.core$compile$fn__5071.invoke(core.clj:5652)
    at clojure.core$compile.invoke(core.clj:5651)
    at user$eval9$fn__16.invoke(form-init4933276377482032885.clj:1)
    at user$eval9.invoke(form-init4933276377482032885.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6703)
    at clojure.lang.Compiler.eval(Compiler.java:6693)
    at clojure.lang.Compiler.load(Compiler.java:7130)
    at clojure.lang.Compiler.loadFile(Compiler.java:7086)
    at clojure.main$load_script.invoke(main.clj:274)
    at clojure.main$init_opt.invoke(main.clj:279)
    at clojure.main$initialize.invoke(main.clj:307)
    at clojure.main$null_opt.invoke(main.clj:342)
    at clojure.main$main.doInvoke(main.clj:420)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:383)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.Var.applyTo(Var.java:700)
    at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No matching ctor found for class io.pedestal.interceptor.helpers$before$fn__6182
    at clojure.lang.Reflector.invokeConstructor(Reflector.java:163)
    at clojure.lang.LispReader$EvalReader.invoke(LispReader.java:1043)
    at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:616)
    at clojure.lang.LispReader.read(LispReader.java:183)
    at clojure.lang.RT.readString(RT.java:1737)
    at ctor_errors.service__init.__init0(Unknown Source)
    at ctor_errors.service__init.<clinit>(Unknown Source)
    ... 27 more
Exception in thread "main" java.lang.ExceptionInInitializerError, compiling:(/tmp/form-init4933276377482032885.clj:1:72)
    at clojure.lang.Compiler.load(Compiler.java:7142)
    at clojure.lang.Compiler.loadFile(Compiler.java:7086)
    at clojure.main$load_script.invoke(main.clj:274)
    at clojure.main$init_opt.invoke(main.clj:279)
    at clojure.main$initialize.invoke(main.clj:307)
    at clojure.main$null_opt.invoke(main.clj:342)
    at clojure.main$main.doInvoke(main.clj:420)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:383)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.Var.applyTo(Var.java:700)
    at clojure.main.main(main.java:37)
Caused by: java.lang.ExceptionInInitializerError
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:274)
    at clojure.lang.RT.loadClassForName(RT.java:2093)
    at clojure.lang.RT.load(RT.java:430)
    at clojure.lang.RT.load(RT.java:411)
    at clojure.core$load$fn__5066.invoke(core.clj:5641)
    at clojure.core$load.doInvoke(core.clj:5640)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5446)
    at clojure.core$compile$fn__5071.invoke(core.clj:5652)
    at clojure.core$compile.invoke(core.clj:5651)
    at user$eval9$fn__16.invoke(form-init4933276377482032885.clj:1)
    at user$eval9.invoke(form-init4933276377482032885.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6703)
    at clojure.lang.Compiler.eval(Compiler.java:6693)
    at clojure.lang.Compiler.load(Compiler.java:7130)
    ... 11 more
Caused by: java.lang.IllegalArgumentException: No matching ctor found for class io.pedestal.interceptor.helpers$before$fn__6182
    at clojure.lang.Reflector.invokeConstructor(Reflector.java:163)
    at clojure.lang.LispReader$EvalReader.invoke(LispReader.java:1043)
    at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:616)
    at clojure.lang.LispReader.read(LispReader.java:183)
    at clojure.lang.RT.readString(RT.java:1737)
    at ctor_errors.service__init.__init0(Unknown Source)
    at ctor_errors.service__init.<clinit>(Unknown Source)
    ... 27 more
Compilation failed: Subprocess failed

@ohpauleez

This comment has been minimized.

Show comment
Hide comment
@ohpauleez

ohpauleez Jan 29, 2015

Member

There is a new interceptor API, and use of the old interceptor macros is discouraged. The macros are multi-layered, and can cause issues generating correct classes at compile time (due to some branching within the macros). This will only happen if you use AOT compilation.

If you need AOT compilation, you must use the API (and the protocol) directly:

(ns example
  (:require [io.pedestal.interceptor.helpers :as interceptor]))

(def my-page
  (interceptor/before
    ::my-page
    (fn [ctx]  (assoc ctx :response (ring-resp/response "this is my page")))

See ring_middlware or body-params for more examples.

Details about the new Interceptor API are in the Pull-Request

Once you confirms this fixes your issue, I'll close out the ticket.

Member

ohpauleez commented Jan 29, 2015

There is a new interceptor API, and use of the old interceptor macros is discouraged. The macros are multi-layered, and can cause issues generating correct classes at compile time (due to some branching within the macros). This will only happen if you use AOT compilation.

If you need AOT compilation, you must use the API (and the protocol) directly:

(ns example
  (:require [io.pedestal.interceptor.helpers :as interceptor]))

(def my-page
  (interceptor/before
    ::my-page
    (fn [ctx]  (assoc ctx :response (ring-resp/response "this is my page")))

See ring_middlware or body-params for more examples.

Details about the new Interceptor API are in the Pull-Request

Once you confirms this fixes your issue, I'll close out the ticket.

@avescodes

This comment has been minimized.

Show comment
Hide comment
@avescodes

avescodes Jan 29, 2015

Member

I wanted to pop in to mention, Pedestal hasn't been extensively tested with Windows, and I know at one point it didn't work very well there.

If you do manage to get things working, we'd love to hear back.

Member

avescodes commented Jan 29, 2015

I wanted to pop in to mention, Pedestal hasn't been extensively tested with Windows, and I know at one point it didn't work very well there.

If you do manage to get things working, we'd love to hear back.

@mavbozo

This comment has been minimized.

Show comment
Hide comment
@mavbozo

mavbozo Jan 29, 2015

Contributor

@ohpauleez Thank you for the solution.I managed to create the uberjar.

I develop a webapp using pedestal 0.3.0 - 0.4.0-SNAPSHOT in windows 7 and so far, I haven't encounter problems from pedestal which make my webapp doesn't run. My webapp runs fine in my windows 7 pc.

I also do some experiment to run my webapp as a war in a jetty container in windows 7 development machine. The webapp also runs fine.

Contributor

mavbozo commented Jan 29, 2015

@ohpauleez Thank you for the solution.I managed to create the uberjar.

I develop a webapp using pedestal 0.3.0 - 0.4.0-SNAPSHOT in windows 7 and so far, I haven't encounter problems from pedestal which make my webapp doesn't run. My webapp runs fine in my windows 7 pc.

I also do some experiment to run my webapp as a war in a jetty container in windows 7 development machine. The webapp also runs fine.

@ohpauleez

This comment has been minimized.

Show comment
Hide comment
@ohpauleez

ohpauleez Jan 29, 2015

Member

Thanks for the update!

Member

ohpauleez commented Jan 29, 2015

Thanks for the update!

@ohpauleez ohpauleez closed this Jan 29, 2015

@martintrojer

This comment has been minimized.

Show comment
Hide comment
@martintrojer

martintrojer Sep 1, 2015

I tried this (removing the defbefore) and that made it possible to create a uberjar.

Unfortunately, I got the exact same error when launching said uberjar!

(pedestal 0.4.0)

martintrojer commented Sep 1, 2015

I tried this (removing the defbefore) and that made it possible to create a uberjar.

Unfortunately, I got the exact same error when launching said uberjar!

(pedestal 0.4.0)

@kirillsalykin

This comment has been minimized.

Show comment
Hide comment
@kirillsalykin

kirillsalykin Sep 1, 2015

i was caught by this too. Fixed with fallback to raw interceptor, but not really handy solution:

(def keywordize-params
  (interceptor
    {:name ::keywordize-params
     :enter
     (fn [context]
      (let [request (:request context)
            new-request (assoc request :params
                          (clojure.walk/keywordize-keys (:params request)))]
        (assoc context :request new-request)))}))

kirillsalykin commented Sep 1, 2015

i was caught by this too. Fixed with fallback to raw interceptor, but not really handy solution:

(def keywordize-params
  (interceptor
    {:name ::keywordize-params
     :enter
     (fn [context]
      (let [request (:request context)
            new-request (assoc request :params
                          (clojure.walk/keywordize-keys (:params request)))]
        (assoc context :request new-request)))}))
@martintrojer

This comment has been minimized.

Show comment
Hide comment
@martintrojer

martintrojer Sep 1, 2015

@ohpauleez can you re-open this issue?

martintrojer commented Sep 1, 2015

@ohpauleez can you re-open this issue?

@ohpauleez

This comment has been minimized.

Show comment
Hide comment
@ohpauleez

ohpauleez Sep 1, 2015

Member

@martintrojer Are you sure you've removed all uses of the interceptor helper macros?

AOT should only work with using the Interceptor API directly.

Above, I mention using interceptor/before, but in all my Pedestal services, I always use interceptor/interceptor directly.

Member

ohpauleez commented Sep 1, 2015

@martintrojer Are you sure you've removed all uses of the interceptor helper macros?

AOT should only work with using the Interceptor API directly.

Above, I mention using interceptor/before, but in all my Pedestal services, I always use interceptor/interceptor directly.

@martintrojer

This comment has been minimized.

Show comment
Hide comment
@martintrojer

martintrojer Sep 1, 2015

@ohpauleez you are right, I had some defbefores in a library I was using.

Going back to sleep.

martintrojer commented Sep 1, 2015

@ohpauleez you are right, I had some defbefores in a library I was using.

Going back to sleep.

bobby pushed a commit to capitalone/cqrs-manager-for-distributed-reactive-services that referenced this issue Apr 19, 2017

bobby added a commit to capitalone/cqrs-manager-for-distributed-reactive-services that referenced this issue Jul 5, 2017

Makefile-based developer workflow (#21)
* Eliminate unused zookeeper.connect config

* Update example pom

* Upgrade kafka-streams dependency
* Rename artifact so as not to conflict with kafka-streams

* .gitignore

* Fix AOT compliation

cf. pedestal/pedestal#308

* Makefile-based developer workflow

* Add Copyright header to `Makefile`

* Rename make target db -> psql

* More Make-idiomatic idempotency/error-suppression
@hlship

This comment has been minimized.

Show comment
Hide comment
@hlship

hlship Jan 16, 2018

Another way to get this exception is when using table routes, and the interceptors (third element in tuple) is a seq, but not a vector, of interceptors. That had my head spinning for 45 minutes!

It came up in my project because I was tweaking some code that dynamically assembles the list of interceptors for a route based on some configuration.

hlship commented Jan 16, 2018

Another way to get this exception is when using table routes, and the interceptors (third element in tuple) is a seq, but not a vector, of interceptors. That had my head spinning for 45 minutes!

It came up in my project because I was tweaking some code that dynamically assembles the list of interceptors for a route based on some configuration.

TomMD added a commit to TomMD/cqrs-manager-for-distributed-reactive-services that referenced this issue Sep 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment