{"id":3648,"date":"2016-04-13T03:13:48","date_gmt":"2016-04-13T03:13:48","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=3648"},"modified":"2016-04-13T03:13:48","modified_gmt":"2016-04-13T03:13:48","slug":"fixing-scala-error-bad-symbolic-reference","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-scala-error-bad-symbolic-reference\/","title":{"rendered":"Fixing scala error:  bad symbolic reference"},"content":{"rendered":"<p>If you write Scala code, you&#8217;re almost guaranteed to end up with incompatible class files somewhere in the chain. This is particularly irritating when it happens within libraries you don&#8217;t control, because the scala compiler apparently decides not to give you any useful information, like so:<\/p>\n<pre>\n[error] bad symbolic reference. A signature in DefaultWrites.class refers to term time\n[error] in package java which is not available.\n[error] It may be completely missing from the current classpath, or the version on\n[error] the classpath might be incompatible with the version used when compiling DefaultWrites.class.\n[error]                   \"id\" -> id,\n<\/pre>\n<p>This is especially irritating because for me it only occurred when I started using some implicit that apparently depended on a Java 8 class, when the rest of the Play JSON library had been working fine.<\/p>\n<p>Basically the cause of this is that you have several points of control: Java 7\/8, Scala 2.10, 2.11, or 2.12 (perhaps a point release).<\/p>\n<p>Within SBT, you control this in several ways:<\/p>\n<pre lang=\"scala\">\nscalaVersion := \"2.10.5\"\n<\/pre>\n<p>If you specify the maven dependencies correctly, SBT will just figure out the right thing. If you copy stuff from people&#8217;s blogs, you may end up with mismatched scala versions, which breaks things:<\/p>\n<pre lang=\"scala\">\nlibraryDependencies += \"com.typesafe.play\" %% \"play-json\" % \"2.4.6\"\n\nlibraryDependencies += \"com.typesafe.akka\" % \"akka-actor_2.10\" % \"2.3.14\" \/\/ don't do this\n<\/pre>\n<p>You may see some blog posts that suggest adding scalacOptions or javacOptions. This is less helpful than you&#8217;d think, because this just tells it what platforms to target, so you can only choose numbers equal to or lower than your current environment. Oddly, no tool I&#8217;ve seen (including Intellij) can find the JVMs you&#8217;ve installed on your machine, so there is no easy way to make a config file that picks one.<\/p>\n<pre>\njavacOptions ++= Seq(\"-source\", \"1.8\", \"-target\", \"1.8\")\nscalacOptions += \"-target:jvm-1.8\"\n<\/pre>\n<p>Thus, a final possible cause for this problem is a bad JAVA_HOME, more likely if you see Java 7 than 8. It is worth making sure you control this carefully, as this problem is only going to get worse (scala 12, 13, etc, Java 9, etc)<\/p>\n<pre>\necho %JAVA_HOME%\nC:\\Program Files\\Java\\jdk1.8.0\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you write Scala code, you&#8217;re almost guaranteed to end up with incompatible class files somewhere in the chain. This is particularly irritating when it happens within libraries you don&#8217;t control, because the scala compiler apparently decides not to give you any useful information, like so: [error] bad symbolic reference. A signature in DefaultWrites.class refers &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/fixing-scala-error-bad-symbolic-reference\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Fixing scala error:  bad symbolic reference&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9],"tags":[300,479,480],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3648"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=3648"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/3648\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=3648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=3648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=3648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}