title: Google App Engine - calling new Gson() creates "java.lang.VerifyError: Cannot inherit from final class"
body: <p>This works when debugging locally but once deployed any servlet call to new Gson() produces this error. I've not been able to google a fix for it. What will fix the issue?</p>
  
  <pre><code>import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {    
      Gson gson = new Gson();
      resp.setContentType("text/plain");
      resp.getWriter().println("Service started.");
  }
  
  
  Uncaught exception from servlet
  java.lang.VerifyError: Cannot inherit from final class
      at com.google.appengine.runtime.Request.process-753f125056d26ae3(Request.java)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:809)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
      at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:374)
      at com.selectshotgolf.game.SelectShotServlet.doGet(SelectShotServlet.java:17)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
      at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
      at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
      at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:326)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
      at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:438)
      at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:445)
      at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
      at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:309)
      at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:301)
      at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:442)
      at java.lang.Thread.run(Thread.java:724)
  </code></pre>
  
  <p>This also works fine locally or deployed:</p>
  
  <pre><code>import com.google.gson.Gson;
  
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {    
      new JsonObject();
      resp.setContentType("text/plain");
      resp.getWriter().println("Service started.");
  }
  </code></pre>
  
  <p>*Edit</p>
  
  <p>I let Eclipse update itself a moment ago and after a restart I had to reset the App Engine Java Build Path. Once reset I now had the option to depend on either com.google.gson.Gson or the repackaged.</p>
  
  <p>This still throws the error above:</p>
  
  <pre><code>import com.google.gson.GsonBuilder;
  
      public &lt;T&gt; T fromJson(String paramName, Class&lt;T&gt; clazz){
          if(gson == null)
              gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
  
          return gson.fromJson(req.getParameter(paramName), clazz);
      }
  </code></pre>
  
  <p>but the following code works fine remotely but with the disturbing message:</p>
  
  <p>"Use of com.google.appengine.repackaged may result in your app breaking without warning."</p>
  
  <p>yikes</p>
  
  <pre><code>import com.google.appengine.repackaged.com.google.gson.GsonBuilder;
  
      public &lt;T&gt; T fromJson(String paramName, Class&lt;T&gt; clazz){
          if(gson == null)
              gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
  
          return gson.fromJson(req.getParameter(paramName), clazz);
      }
  </code></pre>