gwtCompile infinite recursion bug?

6 views
Skip to first unread message

Michael Conrad

unread,
Nov 5, 2025, 2:27:03 PM (10 hours ago) Nov 5
to google-we...@googlegroups.com

Hello all,

I had a recursive setter get created while switching a field’s name.

I ended up with:

public void setSearchTerm(String searchTerm) {
   setSearchTerm(searchTerm);
}

And the gwtCompile just stops and sits there… (I presume after a very very very very long time it would error out?)

Is this a known bug? Feature?

-Mike

Colin Alworth

unread,
Nov 5, 2025, 2:58:36 PM (10 hours ago) Nov 5
to GWT Users
Thanks for calling this out - it has been reported as https://github.com/gwtproject/gwt/issues/9840 (and earlier), and as time permits I've spent some effort trying to better understand it and fix it. TL;DR: The code here is harder to read than usual due to some questionable variable naming choices, but seems rooted in an attempt to optimize by not running all of the JsInliner on the entire program, resulting in missing cases like this. I have a patch that appears to fix it (and makes sense logically), and is just missing some tests to be sure.

Part of the problem here for code that never converges is that the compiler's "optimization level" tracker believes that "9" is the largest numbers can get - when counting compiler passes. That is, if you ask for the max optimization level, that value is "9", and if after 9 passes the compiler hasn't converged, it will keep going. Some quick testing suggests that 8-11 passes seems "pretty good as a max", but I think this means the max should have been 99 (or higher) so that at some point it actually gives up. No error is required here, just "stop, this is pointless" - and likewise, no timeout.

There's technically another heuristic that the Java optimization loop uses, checking if the number of nodes changed/removed is higher than the required baseline rate:
      float nodeChangeRate = stats.getNumMods() / (float) lastNodeCount;
      float sizeChangeRate = (lastNodeCount - nodeCount) / (float) lastNodeCount;
      if (nodeChangeRate <= minChangeRate && sizeChangeRate <= minChangeRate) {
        break;
      }

Unfortunately, once you've hit "9" as your optimization level, this is fixed at "any change at all is good, keep going".

Further, even if we did have a slightly higher baseline rate configured, the JS optimization loop only counts passes, not change rate:
      if ((optimizationLevel < OptionOptimize.OPTIMIZE_LEVEL_MAX && counter > optimizationLevel)
          || !stats.didChange()) {
        break;
      }

And as it happens, that's where the bug is, in optimizing JS, not Java.

I've mused about adding a timeout option also, something like "whatever you've gotten done in 30s is good enough, give up", but the use case is a little weird - impatient devs who still want optimized code, and nondeterministic (but still correct) output? Seems like a recipe for frustration, but that's just my two cents.

As part of this and some other optimization pass enhancements, I'm hoping to improve both how we collect metrics on the compiler performance and how we debug the work it actually does, so that we can more confidently make changes in this area, or at least make it easier for users to report what they're seeing without sharing their entire codebase.

Michael Conrad

unread,
Nov 5, 2025, 4:18:12 PM (9 hours ago) Nov 5
to google-we...@googlegroups.com

so… I should set my optimize to level 8 or less as a work around?

This also impacts PRETTY mode?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-web-toolkit/0938f2a8-7abc-4e48-8d0a-2c90e08c9e95n%40googlegroups.com.

Colin Alworth

unread,
Nov 5, 2025, 4:25:43 PM (8 hours ago) Nov 5
to GWT Users
That's certainly an option (and might make sense if you can't find the bug in the future), but unless you want to have a stack overflow waiting to happen in your JS, I'd instead suggest fixing the method that calls itself with no possibility of escape.

I think fixing setSearchTerm probably makes more sense.

Michael Conrad

unread,
Nov 5, 2025, 7:29:37 PM (5 hours ago) Nov 5
to google-we...@googlegroups.com

It does. And I have. Is there that much difference between optimize level 8 versus optimize level 9?

It took me forever to find the bug though.

I’m doing a whole lot of rewrites related to converting from restygwt to domino-jackson for client side JSON serialize and deserialize. (Migrating to all Jakarta with a final goal of migrating the back-end to Spring Boot).

It would have been helpful it had errored out with (hopefully) an indication of which file was causing the issue instead of costing me most of the day being perplexed as to why it was just sitting there. If it wasn’t for the IDE flagging the method as infinite recursed when I browsed that file looking for anything, I would still be stuck.

It’s being a bit of a pain, as restygwt + gwt-jackson seems to support jackson annotations better than domino-jackson at this point in time and you can’t have gwt-jackson at all on the classpath along with domino-jackson if using anything that inherits ObjectMapper…

Reply all
Reply to author
Forward
0 new messages