Compiler error, reproduced

41 views
Skip to first unread message

Roberto Leibman

unread,
May 23, 2012, 6:12:49 PM5/23/12
to Scala+GWT
Remember I was having a compiler error earlier? well, I still get it
when I try to compile in the gwtc step (the devmode version works
fine, but I now really want to try to package a war and test it in
tomcat)
The error I get only happens if I have this line in the client

GourmetWeb.service =
GWT.create(classOf[GourmetWebService])

The error is:

[java] [ERROR] An internal compiler exception occurred
[java] com.google.gwt.dev.jjs.InternalCompilerException:
Unexpected error during visit.
[java] at
com.google.gwt.dev.jjs.ast.JVisitor.translateException(JVisitor.java:
109)
[java] at
com.google.gwt.dev.jjs.ast.JModVisitor.acceptImmutable(JModVisitor.java:
313)
[java] at
com.google.gwt.dev.jjs.ast.js.JsniMethodBody.traverse(JsniMethodBody.java:
123)
[java] at
com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
[java] at
com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
[java] at
com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265)
[java] at
com.google.gwt.dev.jjs.ast.JMethod.visitChildren(JMethod.java:426)
[java] at
com.google.gwt.dev.jjs.ast.JMethod.traverse(JMethod.java:395)
[java] at
com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
[java] at
com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:273)
[java] at
com.google.gwt.dev.jjs.ast.JModVisitor.accept(JModVisitor.java:265)
[java] at
com.google.gwt.dev.jjs.impl.UnifyAst.mainLoop(UnifyAst.java:893)
[java] at
com.google.gwt.dev.jjs.impl.UnifyAst.exec(UnifyAst.java:618)
[java] at
com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:
532)
[java] at
com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:
33)
[java] at
com.google.gwt.dev.Precompile.precompile(Precompile.java:278)
[java] at
com.google.gwt.dev.Precompile.precompile(Precompile.java:229)
[java] at
com.google.gwt.dev.Precompile.precompile(Precompile.java:141)
[java] at com.google.gwt.dev.Compiler.run(Compiler.java:232)
[java] at com.google.gwt.dev.Compiler.run(Compiler.java:198)
[java] at com.google.gwt.dev.Compiler$1.run(Compiler.java:
170)
[java] at
com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
[java] at
com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:
82)
[java] at com.google.gwt.dev.Compiler.main(Compiler.java:177)
[java] Caused by: java.lang.NoSuchFieldError:
com.dienique.gourmet_web.shared.Categories.category:Ljava/lang/String;
[java] at
com.google.gwt.dev.jjs.impl.UnifyAst.translate(UnifyAst.java:1060)
[java] at com.google.gwt.dev.jjs.impl.UnifyAst.access
$400(UnifyAst.java:120)
[java] at com.google.gwt.dev.jjs.impl.UnifyAst
$UnifyVisitor.endVisit(UnifyAst.java:205)
[java] at com.google.gwt.dev.jjs.impl.UnifyAst
$UnifyVisitor.endVisit(UnifyAst.java:281)
[java] at
com.google.gwt.dev.jjs.ast.js.JsniFieldRef.traverse(JsniFieldRef.java:
54)
[java] at
com.google.gwt.dev.jjs.ast.JModVisitor.traverse(JModVisitor.java:361)
[java] at
com.google.gwt.dev.jjs.ast.JModVisitor.acceptImmutable(JModVisitor.java:
305)
[java] ... 22 more
[java] [ERROR] at Categories_FieldSerializer.java(16): null
category
[java] com.google.gwt.dev.jjs.ast.js.JsniFieldRef
[java] [ERROR] at Categories_FieldSerializer.java(14): /*-
{
[java]
instance.@com.dienique.gourmet_web.shared.Categories::category =
value;
[java] }-*/;
[java] com.google.gwt.dev.jjs.ast.js.JsniMethodBody
[java] [ERROR] at Categories_FieldSerializer.java(14):
private static native void setCategory(Categories instance, String
value);
[java]
[java] com.google.gwt.dev.jjs.ast.JMethod


-----------------------------------------------------------------------
OK... the following code causes the compiler error
package com.dienique.gourmet_web.client
-----------------------------------------------------------------------

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.UmbrellaException
import com.google.gwt.user.client.ui.RootPanel

object GourmetWeb
{
var service: GourmetWebServiceAsync =
null
}

class GourmetWeb extends EntryPoint {
def onModuleLoad(): Unit = {
try
{
GourmetWeb.service =
GWT.create(classOf[GourmetWebService])
GWT.log("Hello World!", null);
} catch {
case ex: UmbrellaException =>
ex.printStackTrace
}
}
}

package com.dienique.gourmet_web.client

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath
import com.dienique.gourmet_web.shared.Recipe

@RemoteServiceRelativePath("gourmetWebService")
trait GourmetWebService extends RemoteService {
def recipes: Array[Recipe]
def recipe(recipeId:Int): Recipe
}
package com.dienique.gourmet_web.client

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.AsyncCallback
import com.dienique.gourmet_web.shared.Recipe

trait GourmetWebServiceAsync {
def recipes(callback: AsyncCallback[Array[Recipe]]): Unit
def recipe(recipeId: Int, callBack: AsyncCallback[Recipe]): Unit
}
package com.dienique.gourmet_web.shared

import scala.runtime._

class Ingredients (
var id: Int ,
var recipeByRefid: Recipe ,
var recipeByRecipeId: Recipe ,
var unit: String ,
var amount: Option[Float] ,
var rangeamount: Option[Float] ,
var item: String ,
var ingkey: String,
var optional: Boolean ,
var shopoptional: Option[Int] ,
var inggroup: String ,
var position: Option[Int] ,
var deleted: Boolean
)extends Serializable {

def this() {
this(
0,//var id: Int ,
null,//var recipeByRefid: Recipe ,
null,//var recipeByRecipeId: Recipe ,
"",//var unit: String ,
None,//var amount: Float ,
None,//var rangeamount: Float ,
"",//var item: String ,
"",//var ingkey: String,
true,//var optional: Boolean ,
None,//var shopoptional: Int ,
"",//var inggroup: String ,
None,//var position: Int ,
false//var deleted: Boolean
)
}
}

package com.dienique.gourmet_web.shared

class Recipe(
var id:Int,
var title:String,
var instructions:String,
var modifications:String,
var cuisine:String,
var rating:Option[Int],
var description:String,
var source:String,
var preptime:Option[Int],
var cooktime:Option[Int],
var servings:Option[Float],
var deleted:Boolean,
var recipeHash:String,
var ingredientHash:String,
var link:String,
var lastModified:Int,
var yields:Option[Float],
var yieldUnit:String,
var image:Array[Byte],
var thumb:Array[Byte],
var ingredientsesForRecipeId:Array[Ingredients],
var ingredientsesForRefid:Array[Ingredients],
var categorieses:Array[Categories]
)
extends Serializable with
com.google.gwt.user.client.rpc.IsSerializable {
def this() = this(
0,// var id:Int,
"",// var title:String,
"",// var instructions:String,
"",// var modifications:String,
"",// var cuisine:String,
None,// var rating:Int,
"",// var description:String,
"",// var source:String,
None,// var preptime:Int,
None,// var cooktime:Int,
None,// var servings:Float,
false,// var deleted:Boolean,
"",// var recipeHash:String,
"",// var ingredientHash:String,
"",// var link:String,
0,// var lastModified:Int,
None,// var yields:Float,
"",// var yieldUnit:String,
null,// var image:Array[Byte],
null,// var thumb:Array[Byte],
null,// var ingredientsesForRecipeId:Array[Ingredients],
null,// var ingredientsesForRefid:Array[Ingredients],
null// var categorieses:Array[Categories]
)
}

package com.dienique.gourmet_web.shared

class Categories (
var id: Int ,
var recipe: Recipe ,
var category: String
)extends Serializable with
com.google.gwt.user.client.rpc.IsSerializable {
def this() = { this(0, null, "") }
}

package com.dienique.gourmet_web.server

import com.google.gwt.user.server.rpc.RemoteServiceServlet
import com.dienique.gourmet_web.client.GourmetWebService
import com.dienique.gourmet_web.shared._
import scala.collection.JavaConversions._
import scala.collection.mutable.ListBuffer

class GourmetWebServiceImpl extends RemoteServiceServlet with
GourmetWebService {
def createRecipe():Recipe ={
null
}
def recipes: Array[Recipe] = {
Array(createRecipe(), createRecipe())
}
def recipe(recipeId:Int) = {
createRecipe()
}
}

Roberto Leibman

unread,
May 29, 2012, 3:19:37 PM5/29/12
to Scala+GWT
OK... I get it it's hard to figure out... does anyone know at least
what part of the project needs to be compiled so I can try to run it
in the debugger to see if I can fix it?
As near as I can tell, scala is taking this:

class MyClass(var myvar:String) {
}

and creating the equivalent java code

public class MyClass {
private String myvar;
public String myvar() {return myvar;}
public void myvar_$eq(String myvar) {this.myvar = myvar;}
}

The gwt compiler is looking for a "public String myvar" and not
finding it. I think I could modify the gwt compiler to either look for
the private field (subverting it by using setAccessible on the field
if necessary) or looking for the special case scala setter myvar_$eq

Nate Bauernfeind

unread,
May 29, 2012, 5:29:29 PM5/29/12
to scal...@googlegroups.com
I have no idea where in the GWT compiler this is happening -- I
haven't had any time to try and figure it out.

However, to get UIBinder to work I had to add some setter / getter
support. Perhaps a similar change somewhere else in the GWT compiler
could fix your issue.

Here's what was necessary for ui binder (I think the top two commits
are sufficient).
https://github.com/scalagwt/scalagwt-gwt/commits/uibinder
Reply all
Reply to author
Forward
0 new messages