Hi ZeroCool, I'm not sure if this will help, and I don't know how the TimSort works but looking at your compare method I'm curious about this particular situation. If you have two users UserA and UserB and UserA has groupRank of 5 and Rep of 3 and UserB has groupRank of 5 and Rep of 3 Then, if you call compare(UserA, UserB) you get a return value of 1 indicating that UserA > UserB But, if you call compare(UserB, UserA) you get a return value of 1 indicating that UserB > UserA So, this situation seems wrong. Now, if I'm interpreting your compare method correctly, then my guess would be that either new data was added to your dataset that hit this particular case or the old mergeSort used by Collections.sort only called compare with the objects in one particular order if it used them multiple times and the new TimSort can call the compare in either order multiple times and it is seeing this discrepancy.
I think you should try re-coding your compare so that if groupRank and Rep are the same for both objects then you return 0 not a 1. I hope this helps, Stephen On Sun, Mar 27, 2011 at 1:19 AM, ZeroCool <[email protected]> wrote: > Hi App Engine Team, > > I see 100% error rate for a servlet in my application. > The function had been working well for months. > The lines of code that generate errors are as following: > > List<Key<User>> memKeys = userDao.getUserKeys(); > Map<Key<User>, User> mem = userDao.get(memKeys); > List<User> memList = new ArrayList<User>(mem.values()); > Collections.sort(memList, comp); > > Comparator<User> comp = new Comparator<User>() > { > @Override > public int compare(User user1, User user2) > { > > int ret = user2.getGroupRank() - user1.getGroupRank(); > if (ret == 0) > { > ret = ((user2.getRep() - user1.getRep()) >= 0 ? 1 : > -1); > } > return ret; > } > }; > > The error is: > > > [27/Mar/2011:00:45:28 -0700] "POST /GM HTTP/1.1" 500 0 - "a. > 2.3.0,gzip(gfe)" "pe-server2.appspot.com" ms=76 cpu_ms=140 > api_cpu_ms=0 cpm_usd=0.003913 > W 2011-03-27 00:45:28.770 > /GM > java.lang.IllegalArgumentException: Comparison method violates its > general contract! > at java.util.TimSort.mergeLo(TimSort.java:747) > at java.util.TimSort.mergeAt(TimSort.java:483) > at java.util.TimSort.mergeCollapse(TimSort.java:408) > at java.util.TimSort.sort(TimSort.java:214) > at java.util.TimSort.sort(TimSort.java:173) > at java.util.Arrays.sort(Arrays.java:1347) > at java.util.Collections.sort(Collections.java:217) > at com.miracle.server.pe.GroupMember.doPost(GroupMember.java:46) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) > 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.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java: > 97) > at org.mortbay.jetty.servlet.ServletHandler > $CachedChain.doFilter(ServletHandler.java:1157) > at > > com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java: > 35) > at org.mortbay.jetty.servlet.ServletHandler > $CachedChain.doFilter(ServletHandler.java:1157) > at > > com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java: > 43) > 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 > > com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java: > 238) > 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 > > com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java: > 76) > at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) > at > > com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java: > 135) > at > com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java: > 261) > at com.google.apphosting.base.RuntimePb$EvaluationRuntime > $2.handleRequest(RuntimePb.java:9285) > at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java: > 437) > at com.google.net.rpc.impl.Server$RpcTask.runInContext(Server.java: > 573) > at com.google.tracing.TraceContext$TraceContextRunnable > $1.run(TraceContext.java:448) > at com.google.tracing.TraceContext.runInContext(TraceContext.java: > 688) > at com.google.tracing.TraceContext > > $AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java: > 326) > at com.google.tracing.TraceContext > $AbstractTraceContextCallback.runInInheritedContext(TraceContext.java: > 318) > at com.google.tracing.TraceContext > $TraceContextRunnable.run(TraceContext.java:446) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: > 1110) > at java.util.concurrent.ThreadPoolExecutor > $Worker.run(ThreadPoolExecutor.java:603) > at java.lang.Thread.run(Thread.java:636) > > > With some googling, I found that the error was related to JDK bugs. > > I'm not using a sorted map or set which will possibly impose such > error: > "In particular the sorted set (or sorted map) will violate the general > contract for set (or map), which is defined in terms of equals." as in > http://download.oracle.com/javase/1.4.2/docs/api/java/util/Comparator.html > > Is there anything I can do to fix the problem? > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine for Java" group. > To post to this group, send email to > [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-appengine-java?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
