简体   繁体   English

IllegalAccessError和代理

[英]IllegalAccessError and proxy

I'm translating this code to Clojure. 我正在将此代码翻译为Clojure。 As you can see, I have to extend the class ArthurFrame , yet I'm getting an IllegalAccessError everytime I use (proxy [ArthurFrame] [] ...) . 如您所见,我必须扩展ArthurFrame类,但是每次使用时都会收到一个IllegalAccessError (proxy [ArthurFrame] [] ...)

Any idea why? 知道为什么吗? Here is the class's source . 这是班级的来历

Thanks! 谢谢!

EDIT: Here is the full error stack for running (proxy [ArthurFrame] []) on the REPL. 编辑: 这是在REPL上运行(代理[ArthurFrame] []) 的完整错误堆栈

EDIT 2 : Actually it seems that even instantiating the class yields an error. 编辑2 :实际上似乎即使实例化该类也会产生错误。 Here is the output from (ArthurFrame. wid) : 这是(ArthurFrame. wid)的输出:

tried to access class com.trolltech.demos.ArthurFrame from class user$eval__2205
  [Thrown class java.lang.IllegalAccessError]

Restarts:
 0: [ABORT] Return to SLIME's top level.

Backtrace:
  0: user$eval__2205.invoke(NO_SOURCE_FILE:1)
  1: clojure.lang.Compiler.eval(Compiler.java:4642)
  2: clojure.core$eval__5254.invoke(core.clj:2031)
  3: swank.commands.basic$eval_region__907.invoke(basic.clj:40)
  4: swank.commands.basic$eval_region__907.invoke(basic.clj:31)
  5: swank.commands.basic$eval__927$listener_eval__929.invoke(basic.clj:54)
  6: clojure.lang.Var.invoke(Var.java:359)
  7: user$eval__2202.invoke(NO_SOURCE_FILE)
  8: clojure.lang.Compiler.eval(Compiler.java:4642)
  9: clojure.core$eval__5254.invoke(core.clj:2031)
 10: swank.core$eval_in_emacs_package__455.invoke(core.clj:59)
 11: swank.core$eval_for_emacs__533.invoke(core.clj:128)
 12: clojure.lang.Var.invoke(Var.java:367)
 13: clojure.lang.AFn.applyToHelper(AFn.java:179)
 14: clojure.lang.Var.applyTo(Var.java:476)
 15: clojure.core$apply__4379.invoke(core.clj:434)
 16: swank.core$eval_from_control__458.invoke(core.clj:66)
 17: swank.core$eval_loop__461.invoke(core.clj:71)
 18: swank.core$spawn_repl_thread__595$fn__627$fn__629.invoke(core.clj:183)
 19: clojure.lang.AFn.applyToHelper(AFn.java:171)
 20: clojure.lang.AFn.applyTo(AFn.java:164)
 21: clojure.core$apply__4379.invoke(core.clj:434)
 22: swank.core$spawn_repl_thread__595$fn__627.doInvoke(core.clj:180)
 23: clojure.lang.RestFn.invoke(RestFn.java:402)
 24: clojure.lang.AFn.run(AFn.java:37)
 25: java.lang.Thread.run(Thread.java:619)

The problem is that ArthurFrame visibility is package not public so the proxy can't access it since the proxy doesn't belong to the package com.trolltech.demos. 问题在于ArthurFrame可见性不是包公开的,因此代理无法访问它,因为代理不属于com.trolltech.demos包。 You have to make ArthurFrame public. 您必须将ArthurFrame公开。

The most likely cause of your problem is that something has not been recompiled. 造成问题的最可能原因是某些内容尚未重新编译。 Here's the javadoc description of the IllegalAccessError exception: 这是IllegalAccessError异常的javadoc描述:

Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to. 如果应用程序尝试访问或修改字段,或调用它无权访问的方法,则抛出该异常。

Normally, this error is caught by the compiler; 通常,此错误由编译器捕获; this error can only occur at run time if the definition of a class has incompatibly changed. 如果类的定义发生了不兼容的更改,则只有在运行时才会发生此错误。

To be more specific, this normally happens when you have classes A and B , where B depends on some members of A . 更具体地说,这通常发生在您拥有类AB ,其中B依赖于A某些成员。 Then you do something like this: 然后,您可以执行以下操作:

  1. You compile A , then B . 您先编译A ,然后编译B

  2. Make an incompatible change to A and recompile it without recompiling B . A进行不兼容的更改,然后重新编译而不重新编译B In this case, the change would involve reducing the visibility of some member of A that B uses so that the member should no longer be visible to B . 在这种情况下,更改将涉及降低B使用的A的某个成员的可见性,以使该成员不再对B可见。

  3. Run an application that uses A and B and and you will get an IllegalAccessError . 运行使用AB的应用程序,您将收到IllegalAccessError

EDIT 编辑

The proxy class that is trying to do the accessing looks like it must have been generated by the Clojure compiler. 尝试进行访问的代理类看起来必须由Clojure编译器生成。 So maybe there is a Clojure compiler bug ... or maybe you changed the visibility of ArthurFrame after you ran the Clojure compiler. 因此,可能存在Clojure编译器错误...或者运行了Clojure编译器后,您更改了ArthurFrame的可见性。 Either way, one possible fix is to change the visibility of the ArthurFrame to public . 无论哪种方式,一种可能的解决方法是将ArthurFrame的可见性更改为public

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM