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

NullPointerException during icode #93

Closed
maiflai opened this issue Jan 30, 2015 · 23 comments
Closed

NullPointerException during icode #93

maiflai opened this issue Jan 30, 2015 · 23 comments

Comments

@maiflai
Copy link
Contributor

maiflai commented Jan 30, 2015

Hi,

scoverage/gradle-scoverage#35 was raised recently in the gradle-scoverage repository, but I think it's more likely a problem in the compiler plugin.

Compiling with 2.11.5 gives a NullPointerException with no message.

Compiling with 2.10.4 gives the following:

while compiling: /Users/stu/Documents/Eclipse/kafka/core/src/main/scala/kafka/utils/ZkUtils.scala
        during phase: icode
     library version: version 2.10.4
    compiler version: version 2.10.4
  reconstructed args: -bootclasspath /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/classes:/Users/stu/.gradle/caches/modules-2/files-2.1/org.scala-lang/scala-library/2.10.4/9aae4cb1802537d604e03688cab744ff47b31a7d/scala-library-2.10.4.jar -classpath /Users/stu/Documents/Eclipse/kafka/core/build/classes/scoverage:/Users/stu/Documents/Eclipse/kafka/clients/build/libs/kafka-clients-0.8.3-SNAPSHOT.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/org.apache.zookeeper/zookeeper/3.4.6/1b2502e29da1ebaade2357cd1de35a855fa3755/zookeeper-3.4.6.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/com.101tec/zkclient/0.3/dedcf2b53fb742adba7080ac3aed781694ba616e/zkclient-0.3.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/com.yammer.metrics/metrics-core/2.2.0/f82c035cfa786d3cbec362c38c22a5f5b1bc8724/metrics-core-2.2.0.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/net.sf.jopt-simple/jopt-simple/3.2/d625f12ba08083c8c16dcedd5396ec730e9e77ab/jopt-simple-3.2.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.6/562424e36df3d2327e8e9301a76027fca17d54ea/slf4j-api-1.7.6.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/org.xerial.snappy/snappy-java/1.1.1.6/e3f12835a135c0d253bee4dbbe74d37ce35d7269/snappy-java-1.1.1.6.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/net.jpountz.lz4/lz4/1.2.0/cd301e9a481eae5b68c53267100aeca43b782b9f/lz4-1.2.0.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.6.1/b                                                                                             d245d6746cdd4e6203e976e21d597a46f115802/slf4j-log4j12-1.6.1.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/log4j/log4j/1.2.16/7999a63bfccbc7c247a9aea10d83d4272bd492c6/log4j-1.2.16.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/org.scoverage/gradle-scoverage/1.0-5-g9c68988/19bd553df3d6ced75d56b9912a10672af896ba9e/gradle-scoverage-1.0-5-g9c68988.jar:/Users/stu/.gradle/caches/modules-2/files-2.1/org.scoverage/scalac-scoverage-runtime_2.10/1.0.2/92a4a183161a94d80b02697228dc9198dc12e0d8/scalac-scoverage-runtime_2.10-1.0.2.jar -deprecation -Yrangepos -Xplugin:/Users/stu/.gradle/caches/modules-2/files-2.1/org.scoverage/scalac-scoverage-plugin_2.10/1.0.2/90936f85dfa01ba63f31f11544dcec2558281426/scalac-scoverage-plugin_2.10-1.0.2.jar -unchecked -P:scoverage:dataDir:/Users/stu/Documents/Eclipse/kafka/core/build/scoverage

  last tree to typer: Literal(Constant(Class))
              symbol: null
   symbol definition: null
                 tpe: Class(classOf[java.lang.Class])
       symbol owners: 
      context owners: anonymous class anonfun$getAllPartitions$1 -> package utils

== Enclosing template or block ==

Template( // val <local $anonfun>: <notype>, tree.tpe=kafka.utils.anonfun$getAllPartitions$1
  "scala.runtime.AbstractFunction1", "scala.Serializable" // parents
  ValDef(
    private
    "_"
    <tpt>
    <empty>
  )
  // 4 statements
  DefDef( // final def apply(topic: String): Seq
    <method> final <triedcooking>
    "apply"
    []
    // 1 parameter list
    ValDef( // topic: String
      <param> <triedcooking>
      "topic"
      <tpt> // tree.tpe=String
      <empty>
    )
    <tpt> // tree.tpe=Seq
    Block( // tree.tpe=Seq
      Apply( // def invoked(id: Int,dataDir: String): Unit in object Invoker, tree.tpe=Unit
        "scoverage"."Invoker"."invoked" // def invoked(id: Int,dataDir: String): Unit in object Invoker, tree.tpe=(id: Int, dataDir: String)Unit
        // 2 arguments
        25416
        "/Users/stu/Documents/Eclipse/kafka/core/build/scoverage"
      )
      Apply( // final def $asInstanceOf[T0 >: ? <: ?](): T0 in class Object, tree.tpe=Seq
        TypeApply( // final def $asInstanceOf[T0 >: ? <: ?](): T0 in class Object, tree.tpe=()Seq
          ZkUtils.this.getChildren(ZkUtils$$anonfun$getAllPartitions$1.this.zkClient$3, {
  scoverage.Invoker.invoked(25411, "/Users/stu/Documents/Eclipse/kafka/core/build/scoverage");
  ZkUtils.this.getTopicPartitionsPath(topic)
}).map({
  (new anonymous class anonfun$apply$11(ZkUtils$$anonfun$getAllPartitions$1.this): Function1)
}, {
  scoverage.Invoker.invoked(25413, "/Users/stu/Documents/Eclipse/kafka/core/build/scoverage");
  collection.this.Seq.canBuildFrom()
}).$asInstanceOf[collection.TraversableLike]().map({
  (new anonymous class anonfun$apply$12(ZkUtils$$anonfun$getAllPartitions$1.this, topic): Function1)
}, {
  scoverage.Invoker.invoked(25415, "/Users/stu/Documents/Eclipse/kafka/core/build/scoverage");
  collection.this.Seq.canBuildFrom()
})."$asInstanceOf" // final def $asInstanceOf[T0 >: ? <: ?](): T0 in class Object, tree.tpe=[T0 >: ? <: ?]()T0
          <tpt> // tree.tpe=Seq
        )
        Nil
      )
    )
  )
  DefDef( // final def apply(v1: Object): Object
    <method> final <bridge>
    "apply"
    []
    // 1 parameter list
    ValDef( // v1: Object
      <param> <triedcooking>
      "v1"
      <tpt> // tree.tpe=Object
      <empty>
    )
    <tpt> // tree.tpe=Object
    Apply( // final def apply(topic: String): Seq, tree.tpe=Seq
      ZkUtils$$anonfun$getAllPartitions$1.this."apply" // final def apply(topic: String): Seq, tree.tpe=(topic: String)Seq
      Apply( // final def $asInstanceOf[T0 >: ? <: ?](): T0 in class Object, tree.tpe=String
        TypeApply( // final def $asInstanceOf[T0 >: ? <: ?](): T0 in class Object, tree.tpe=()String
          "v1"."$asInstanceOf" // final def $asInstanceOf[T0 >: ? <: ?](): T0 in class Object, tree.tpe=[T0 >: ? <: ?]()T0
          <tpt> // tree.tpe=String
        )
        Nil
      )
    )
  )
  ValDef( // private[this] val zkClient$3: org.I0Itec.zkclient.ZkClient
    private <local> <synthetic> <paramaccessor> <triedcooking>
    "zkClient$3"
    <tpt> // tree.tpe=org.I0Itec.zkclient.ZkClient
    <empty>
  )
  DefDef( // def <init>(zkClient$3: org.I0Itec.zkclient.ZkClient): kafka.utils.anonfun$getAllPartitions$1
    <method> <triedcooking>
    "<init>"
    []
    // 1 parameter list
    ValDef( // zkClient$3: org.I0Itec.zkclient.ZkClient
      <param> <synthetic> <triedcooking>
      "zkClient$3"
      <tpt> // tree.tpe=org.I0Itec.zkclient.ZkClient
      <empty>
    )
    <tpt> // tree.tpe=kafka.utils.anonfun$getAllPartitions$1
    Block( // tree.tpe=Unit
      // 2 statements
      Assign( // tree.tpe=Unit
        ZkUtils$$anonfun$getAllPartitions$1.this."zkClient$3" // private[this] val zkClient$3: org.I0Itec.zkclient.ZkClient, tree.tpe=org.I0Itec.zkclient.ZkClient
        "zkClient$3" // zkClient$3: org.I0Itec.zkclient.ZkClient, tree.tpe=org.I0Itec.zkclient.ZkClient
      )
      Apply( // def <init>(): scala.runtime.AbstractFunction1 in class AbstractFunction1, tree.tpe=scala.runtime.AbstractFunction1
        ZkUtils$$anonfun$getAllPartitions$1.super."<init>" // def <init>(): scala.runtime.AbstractFunction1 in class AbstractFunction1, tree.tpe=()scala.runtime.AbstractFunction1
        Nil
      )
      ()
    )
  )
)

== Expanded type of tree ==

ConstantType(value = Constant(Class))

uncaught exception during compilation: java.lang.NullPointerException
@maiflai maiflai changed the title NullPointerException during code NullPointerException during icode Jan 30, 2015
@sksamuel
Copy link
Member

Can you isolate the code that causes this, ideally without any external deps.

@maiflai
Copy link
Contributor Author

maiflai commented Jan 30, 2015

I'll see what we can do - it was a long shot that you'd recognise the problem just from the error message :-)

@sksamuel
Copy link
Member

Lol no chance, I have to duplicate the problem and figure out what construct is causing the error in the AST.

@maiflai
Copy link
Contributor Author

maiflai commented Jan 31, 2015

Well that's a piece of code I don't want to go near again.

I can fix the issue by commenting out a return inside a catch block at line 366:

      case e1: ZkBadVersionException =>
        optionalChecker match {
          case Some(checker) => //return checker(client, path, data)
          case _ => debug("Checker method is not passed skipping zkData match")
        }
        warn("Conditional update of path %s with data %s and expected version %d failed due to %s".format(path, data,
          expectVersion, e1.getMessage))
        (false, -1)
      case e2: Exception =>

I can produce a NullPointerException (but not exactly the same one) with the following:

object bob {
  def fail(): Boolean = {
    try {
      true
    } catch {
      case _ : Throwable => 
        Option(true) match {
          case Some(bool) => return bool // comment this return and instrumentation succeeds
          case _ =>
        }
        false
    }
  }
}

@sksamuel
Copy link
Member

It's likely return statements themselves are not handled well then. I will fix this.

sksamuel added a commit that referenced this issue Jan 31, 2015
@sksamuel
Copy link
Member

I can't even get it to pass with the return commented out.

@maiflai
Copy link
Contributor Author

maiflai commented Jan 31, 2015

That's odd - jdk8, scalac 2.10.4? I'll post a full command line when I get home, sorry.

@sksamuel
Copy link
Member

No 2.11.4 and jdk8.

On 31 January 2015 at 15:39, maiflai notifications@github.com wrote:

That's odd - jdk8, scalac 2.10.4? I'll post a full command line when I get
home, sorry.


Reply to this email directly or view it on GitHub
#93 (comment)
.

@maiflai
Copy link
Contributor Author

maiflai commented Jan 31, 2015

Ok, will check that too. 2.10 gave a more detailed error message so I was working from that earlier.

@maiflai
Copy link
Contributor Author

maiflai commented Feb 1, 2015

Sorry, I was using version 1.0.2 of the plugin, and yes, that particular object passes when I use 1.0.4

I think I've managed to break 1.0.4 by adding a function call to the return:

object bob {
  def recover(it: Boolean): Boolean = it
  def fail(): Boolean = {
    try {
      true
    } catch {
      case _ : Throwable => 
        Option(true) match {
          case Some(bool) => return recover(bool) // comment this return and instrumentation succeeds
          case _ =>
        }
        false
    }
  }
}

@sksamuel
Copy link
Member

sksamuel commented Feb 1, 2015

Still Scala 2.10 or 2.11?

On 1 February 2015 at 10:39, maiflai notifications@github.com wrote:

Sorry, I was using version 1.0.2 of the plugin, and yes, that particular
object passes when I use 1.0.4

I think I've managed to break 1.0.4 by adding a function call to the
return:

object bob {
def recover(it: Boolean): Boolean = it
def fail(): Boolean = {
try {
true
} catch {
case _ : Throwable =>
Option(true) match {
case Some(bool) => return recover(bool) // comment this return and instrumentation succeeds
case _ =>
}
false
}
}
}


Reply to this email directly or view it on GitHub
#93 (comment)
.

@maiflai
Copy link
Contributor Author

maiflai commented Feb 1, 2015

2.10 definitely, I think 2.11 as well.

I created #95 with a failing test

@sksamuel
Copy link
Member

sksamuel commented Feb 1, 2015

2.10 is mostly unsupported by the plugin, because of AST issues. If it
fails on 2.11 I think I should focus there.

On 1 February 2015 at 11:37, maiflai notifications@github.com wrote:

2.10 definitely, I think 2.11 as well.

I created #95
#95 with a
failing test


Reply to this email directly or view it on GitHub
#93 (comment)
.

@maiflai
Copy link
Contributor Author

maiflai commented Feb 1, 2015

Ah, ok, thanks.

Re 2.11 - I tried building the plugin with sbt +test, which I thought would build cross-version. However it failed to compile with an xml error.

Sorry, I've not got the error to hand, but please could you let me know if the updated test fails with 2.11?

@Kwestor
Copy link
Contributor

Kwestor commented Feb 2, 2015

One that was merged into master do fail on 2.11.4.

@Kwestor Kwestor mentioned this issue Feb 2, 2015
@maiflai
Copy link
Contributor Author

maiflai commented Feb 2, 2015

Sorry, that was intended to demonstrate a failing test, and probably my fault for submitting a PR to master. It might be that Stephen has a plan for fixing it in the near future?

I think there are a few strategies for coping with this sort of thing with Git - it's not quite the same as commiting to trunk with Subversion or CVS.

@sksamuel
Copy link
Member

sksamuel commented Feb 2, 2015

I am going to look at it soon - and personally, since I'm really the only
person doing any major dev on master on this, I don't care if commit broken
code as we preagreed it.

On 2 February 2015 at 20:12, maiflai notifications@github.com wrote:

Sorry, that was intended to demonstrate a failing test, and probably my
fault for submitting a PR to master. It might be that Stephen has a plan
for fixing it in the near future?

I think there are a few strategies for coping with this sort of thing with
Git - it's not quite the same as commiting to trunk with Subversion or CVS.


Reply to this email directly or view it on GitHub
#93 (comment)
.

@maiflai
Copy link
Contributor Author

maiflai commented Feb 2, 2015

Yep, cheers, much appreciated.

@Kwestor
Copy link
Contributor

Kwestor commented Feb 2, 2015

Yep, but now it will be a part of community build, which suggest test
should pass by default.

Also, you are only person doing any major dev on master as long as someone
does not fork project to implement something and stumble on failing test
without any comment describing that it is supposed to fail.

2015-02-02 21:35 GMT+01:00 maiflai notifications@github.com:

Yep, cheers, much appreciated.


Reply to this email directly or view it on GitHub
#93 (comment)
.

@sksamuel
Copy link
Member

sksamuel commented Feb 2, 2015

Good points.

On 2 February 2015 at 22:02, Jerzy Müller notifications@github.com wrote:

Yep, but now it will be a part of community build, which suggest test
should pass by default.

Also, you are only person doing any major dev on master as long as someone
does not fork project to implement something and stumble on failing test
without any comment describing that it is supposed to fail.

2015-02-02 21:35 GMT+01:00 maiflai notifications@github.com:

Yep, cheers, much appreciated.


Reply to this email directly or view it on GitHub
<
https://github.com/scoverage/scalac-scoverage-plugin/issues/93#issuecomment-72532362>

.


Reply to this email directly or view it on GitHub
#93 (comment)
.

@Kwestor
Copy link
Contributor

Kwestor commented Feb 2, 2015

It wasn't a big issue for me, as I'm reading all issues now, but for
someone else it's nice to have master building. Especially when you can
just mark test as failing :)

2015-02-02 23:04 GMT+01:00 Stephen Samuel notifications@github.com:

Good points.

On 2 February 2015 at 22:02, Jerzy Müller notifications@github.com
wrote:

Yep, but now it will be a part of community build, which suggest test
should pass by default.

Also, you are only person doing any major dev on master as long as
someone
does not fork project to implement something and stumble on failing test
without any comment describing that it is supposed to fail.

2015-02-02 21:35 GMT+01:00 maiflai notifications@github.com:

Yep, cheers, much appreciated.


Reply to this email directly or view it on GitHub
<

https://github.com/scoverage/scalac-scoverage-plugin/issues/93#issuecomment-72532362>

.


Reply to this email directly or view it on GitHub
<
https://github.com/scoverage/scalac-scoverage-plugin/issues/93#issuecomment-72547713>

.


Reply to this email directly or view it on GitHub
#93 (comment)
.

@dskrvk
Copy link

dskrvk commented Jan 19, 2016

Probably caused by SI-8979. Suggested workarounds are to remove return statements (worked in my case) or to use the new compiler backend (-Ybackend:GenBCode).

@ckipp01
Copy link
Member

ckipp01 commented May 10, 2021

I want to assume that this is probably no longer an issue seeing that it's related to 2.10 and 2.11. With modern Scala versions if you still find that this is an issue, please do reopen.

@ckipp01 ckipp01 closed this as completed May 10, 2021
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

5 participants