Uploaded image for project: 'Magnolia UI'
  1. Magnolia UI
  2. MGNLUI-3755

Possible StackOverflow when DefinitionCloner tries to clone i18n proxies

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • 5.4.5
    • 5.4.3
    • None
    • None
    • Kromeriz 28
    • 2

      Given the fact that I really wasn't able to realize why this only happens with some specific configured definition and not with others this problem really drived me nuts for a while...

      Use case: I simply tried to use the action "move" in a custom content app. I simply configured the OpenMoveDialogAction which uses MoveDialogPresenterImpl. Although the same identical configuration seems to work in existing apps (e.g. works fine in the DAM app) when I tried it in my content app it consistently blowed up with a stack overflow exception with the following stack:

      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
      	at com.rits.cloning.Cloner.cloneInternal(Cloner.java:439)
      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
      	at com.rits.cloning.Cloner.cloneInternal(Cloner.java:439)
      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
      	at com.rits.cloning.Cloner.cloneInternal(Cloner.java:439)
      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
      	at com.rits.cloning.Cloner.cloneInternal(Cloner.java:439)
      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
      	at com.rits.cloning.Cloner.cloneInternal(Cloner.java:439)
      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
      	at com.rits.cloning.Cloner.cloneInternal(Cloner.java:439)
      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
      	at com.rits.cloning.Cloner.cloneInternal(Cloner.java:439)
      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
      	at com.rits.cloning.Cloner.cloneInternal(Cloner.java:439)
      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
      	at com.rits.cloning.Cloner.cloneInternal(Cloner.java:439)
      	at com.rits.cloning.Cloner.cloneObject(Cloner.java:463)
              [... tons of identical rows]
      

      even worst, most of the time the whole jvm crashed after this error.

      It took a lot to debug it but I finally traced down the source of the problem in the clone done in MoveDialogPresenterImpl:

              ConfiguredWorkbenchDefinition workbenchDefinition = (ConfiguredWorkbenchDefinition) cloner
                  .deepClone(subAppDescriptor.getWorkbench());
      

      I double checked I had nothing strange in my workbench definition and I also tried making the configuration identical to the one in working apps but no way, the stack overflow error was always there.
      I tried debugging the cloning process and at the end I traced down the problem to be in this part:

      > cloning class java.lang.reflect.Method -- public abstract java.lang.Object info.magnolia.i18nsystem.I18nParentable.getI18nContextParent()
      > cloning class info.magnolia.i18nsystem.proxytoys.FilteringMethodDecorator -- info.magnolia.i18nsystem.proxytoys.FilteringMethodDecorator@2b79e9a1
      > cloning class info.magnolia.i18nsystem.proxytoys.I18nTextMethodDecorator -- info.magnolia.i18nsystem.proxytoys.I18nTextMethodDecorator@ae4a60c
      > cloning class info.magnolia.i18nsystem.TranslationServiceImpl -- info.magnolia.i18nsystem.TranslationServiceImpl@225ad7ee
      > cloning class info.magnolia.i18nsystem.DefaultMessageBundlesLoader -- info.magnolia.i18nsystem.DefaultMessageBundlesLoader@2f5dfa5d
      

      The definitions configured are proxied by the i18n system so the clone also clones I18nParentable. It goes down to I18nTextMethodDecorator which in turns has references to

          private final TranslationService translationService;
          private final LocaleProvider localeProvider;
          private I18nKeyGenerator keyGenerator;
      

      when those fields are reached the cloner now gets access to all the jackrabbit classes and somewhere to the classloader itself, trying to serialize and clone all the objects in the JVM :o

      As said, I didn't understand why this is always happening on some situations and not other, I fear it may be due to the order of modules loaded or something not really predictable. Realized that, it seems that this could be fixed easily by adding:

              cloner.dontCloneInstanceOf(I18nParentable.class);
      

      to info.magnolia.ui.contentapp.DefinitionCloner. I am now living with a patched version of definitionCloner to avoid this problem at all... do you have an opinion in adding this exclusion by default in definitionCloner? Or any other solution that could similarly avoid this kind of situation with i18n proxies?

        Acceptance criteria

              rkovarik Roman Kovařík
              fgiust Fabrizio Giustina
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD

                    Estimated:
                    Original Estimate - Not Specified
                    Not Specified
                    Remaining:
                    Remaining Estimate - 0d
                    0d
                    Logged:
                    Time Spent - 5h
                    5h