tools.analyzer

AbstractMethodError exception when trying to get metadata on literal record in code

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

I do not know if this is a problem with the analyzer, or something in Clojure itself, because attempting to pprint the read-in form with the problem record literal also causes it to throw an AbstractMethodError.

(ns tryanalyzer.try13)

(defrecord RecordTest [a b])

(defn mytest []
  (= (RecordTest. 1 2)
     #tryanalyzer.try13.RecordTest{:a 1, :b 2}))

Activity

Hide
Nicola Mometto added a comment -

I'm sorry, I don't understand what's throwing here.
This works fine for me

clojure.tools.analyzer.jvm> (defrecord RecordTest [a b])
clojure.tools.analyzer.jvm.RecordTest
clojure.tools.analyzer.jvm> (analyze ^:foo #clojure.tools.analyzer.jvm.RecordTest{} (empty-env))
{:tag clojure.tools.analyzer.jvm.RecordTest, :children [:meta], :meta {:tag clojure.lang.IPersistentMap, :op :const, :env {:context :expr, :ns clojure.tools.analyzer.jvm}, :type :map, :literal? т, :form {:foo т}}, :op :const, :env {:context :expr, :ns clojure.tools.analyzer.jvm}, :type :record, :literal? т, :form #clojure.tools.analyzer.jvm.RecordTest{:a ∅, :b ∅}}
Show
Nicola Mometto added a comment - I'm sorry, I don't understand what's throwing here. This works fine for me
clojure.tools.analyzer.jvm> (defrecord RecordTest [a b])
clojure.tools.analyzer.jvm.RecordTest
clojure.tools.analyzer.jvm> (analyze ^:foo #clojure.tools.analyzer.jvm.RecordTest{} (empty-env))
{:tag clojure.tools.analyzer.jvm.RecordTest, :children [:meta], :meta {:tag clojure.lang.IPersistentMap, :op :const, :env {:context :expr, :ns clojure.tools.analyzer.jvm}, :type :map, :literal? т, :form {:foo т}}, :op :const, :env {:context :expr, :ns clojure.tools.analyzer.jvm}, :type :record, :literal? т, :form #clojure.tools.analyzer.jvm.RecordTest{:a ∅, :b ∅}}
Hide
Nicola Mometto added a comment -

Ok I understood what you mean.

This is not a bug, you need to evaluate the defrecord in order to be able to create an instance in read-time.

This is IIRC different than what Compiler.java does, as it compiled the record at analysis time instead of compile time, but it's by design that tools.analyzer/emitter separate evaluation from analysis..

Show
Nicola Mometto added a comment - Ok I understood what you mean. This is not a bug, you need to evaluate the defrecord in order to be able to create an instance in read-time. This is IIRC different than what Compiler.java does, as it compiled the record at analysis time instead of compile time, but it's by design that tools.analyzer/emitter separate evaluation from analysis..
Hide
Andy Fingerhut added a comment -

Nicola, I am pretty sure that I am getting this error even though I am evaluating the defrecord before creating the instance.

Steps to reproduce: Install latest versions of tools.analyzer and tools.analyzer.jvm in your local Maven repo with 'lein install'. Then do the following steps to install locally the latest version of Eastwood I am testing with and seeing the issue:

git clone git://github.com/jafingerhut/eastwood.git
cd eastwood
git checkout try-upgrade-to-tools.analyzer.jvm
LEIN_SNAPSHOTS_IN_RELEASE=1 lein install

Then inside of a project that contains the namespace tryanalyzer.try13 in the description, perhaps renamed to whatever namespace you like, run this command:

lein eastwood ':namespaces [tryanalyzer.try13]}'

I get the AbstractMethodError thrown. Here are some function calls in the call stack, down to the part where I am calling eval on each form after analyzing, before reading and analyzing the next form in the file:

eastwood.core/run-eastwood

eastwood.core/lint-ns

eastwood.analyze-ns/analyze-ns

eastwood.analyze-ns/analyze-file - This was copied from jvm.tools.analyzer's function analyze-file, and then modified significantly. It is the one that calls Clojure's eval function after calling eastwood.jvm/analyze (below) on each form read from the file. It is the most likely place I would guess for there to be mistakes in the way I am calling analyze, in particular with its current choice of argument for the env.

eastwood.jvm/analyze - The comment at beginning of file indicates which file from tools.analyzer.jvm this is nearly an exact copy of.

Show
Andy Fingerhut added a comment - Nicola, I am pretty sure that I am getting this error even though I am evaluating the defrecord before creating the instance. Steps to reproduce: Install latest versions of tools.analyzer and tools.analyzer.jvm in your local Maven repo with 'lein install'. Then do the following steps to install locally the latest version of Eastwood I am testing with and seeing the issue:
git clone git://github.com/jafingerhut/eastwood.git
cd eastwood
git checkout try-upgrade-to-tools.analyzer.jvm
LEIN_SNAPSHOTS_IN_RELEASE=1 lein install
Then inside of a project that contains the namespace tryanalyzer.try13 in the description, perhaps renamed to whatever namespace you like, run this command:
lein eastwood ':namespaces [tryanalyzer.try13]}'
I get the AbstractMethodError thrown. Here are some function calls in the call stack, down to the part where I am calling eval on each form after analyzing, before reading and analyzing the next form in the file: eastwood.core/run-eastwood eastwood.core/lint-ns eastwood.analyze-ns/analyze-ns eastwood.analyze-ns/analyze-file - This was copied from jvm.tools.analyzer's function analyze-file, and then modified significantly. It is the one that calls Clojure's eval function after calling eastwood.jvm/analyze (below) on each form read from the file. It is the most likely place I would guess for there to be mistakes in the way I am calling analyze, in particular with its current choice of argument for the env. eastwood.jvm/analyze - The comment at beginning of file indicates which file from tools.analyzer.jvm this is nearly an exact copy of.
Hide
Nicola Mometto added a comment -

I've investigated a bit on this after being able to reproduce, it looks like it's a classloader issue but it's not clear to me whether I'm doing something I'm not supposed to do or if it's a Clojure bug.

It should be noted that the issue is not there when trying on the repl.

I'll try to find a solution but my understanding of how clojure's dynamic classloader works is really basic so this might take me a while

Show
Nicola Mometto added a comment - I've investigated a bit on this after being able to reproduce, it looks like it's a classloader issue but it's not clear to me whether I'm doing something I'm not supposed to do or if it's a Clojure bug. It should be noted that the issue is not there when trying on the repl. I'll try to find a solution but my understanding of how clojure's dynamic classloader works is really basic so this might take me a while
Hide
Nicola Mometto added a comment -

OK, I pushed a fix: https://github.com/clojure/tools.analyzer.jvm/commit/feecc5be7e536ca6408cd7a2a48ac178cc7e25b9

I don't like this fix at all, I have a better fix for this in my local eastwood branch but unfortunately it's not reliable (it doesn't work for e.g. (do (deftype x []) 1))

This'll have to do.

Show
Nicola Mometto added a comment - OK, I pushed a fix: https://github.com/clojure/tools.analyzer.jvm/commit/feecc5be7e536ca6408cd7a2a48ac178cc7e25b9 I don't like this fix at all, I have a better fix for this in my local eastwood branch but unfortunately it's not reliable (it doesn't work for e.g. (do (deftype x []) 1)) This'll have to do.
Hide
Andy Fingerhut added a comment -

I think this issue is in the latest release of tools.analyzer(.jvm) again. Worth reopening?

Show
Andy Fingerhut added a comment - I think this issue is in the latest release of tools.analyzer(.jvm) again. Worth reopening?
Hide
Nicola Mometto added a comment -

Not the same issue, we've been hitten by this http://dev.clojure.org/jira/browse/CLJ-1105 bug.

Fixed for <=clojure-1.6.0-alpha3 with https://github.com/clojure/tools.analyzer/commit/4981916afb44dcdcc9d6866f46cb55287400213b

Show
Nicola Mometto added a comment - Not the same issue, we've been hitten by this http://dev.clojure.org/jira/browse/CLJ-1105 bug. Fixed for <=clojure-1.6.0-alpha3 with https://github.com/clojure/tools.analyzer/commit/4981916afb44dcdcc9d6866f46cb55287400213b

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: