Uploaded image for project: 'PUBLIC - Liferay Documentation'
  1. PUBLIC - Liferay Documentation
  2. LRDOCS-6316

Following the 'Overriding a Module's Language Keys' tutorial results in StackOverflowError

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Fix Version/s: 7.0.x, 7.1.x
    • Component/s: Documentation
    • Labels:
      None
    • Type of Documentation:
      Developer: Tutorials

      Description

      Per Norbert Kocsis:

      The Overriding a Module's Language Keys' tutorial is wrong. https://dev.liferay.com/hu/develop/tutorials/-/knowledge_base/7-1/overriding-a-modules-language-keys

      @Component(
          immediate = true,
          property = {
             "bundle.symbolic.name=com.liferay.blogs.web",
             "resource.bundle.base.name=content.Language",
             "servlet.context.name=blogs-web"
          }
      )
      public class MyBlogsResourceBundleLoader implements ResourceBundleLoader {
      
          @Override
          public ResourceBundle loadResourceBundle(Locale locale) {
              return _resourceBundleLoader.loadResourceBundle(locale);
          }
      
          @Reference(
             target = "(&(bundle.symbolic.name=com.liferay.blogs.web)(!(component.name=com.liferay.docs.override.moduleresourcebundle.MyBlogsResourceBundleLoader)))"
          )
          public void setResourceBundleLoader(
             ResourceBundleLoader resourceBundleLoader) {
      
             _resourceBundleLoader = new AggregateResourceBundleLoader(
               new CacheResourceBundleLoader(
                new ClassResourceBundleLoader(
                    "content.Language",
                    MyBlogsResourceBundleLoader.class.getClassLoader())),
               resourceBundleLoader);
          }
      
          private AggregateResourceBundleLoader _resourceBundleLoader;
      
      }
      

      In the above class we create an endless recursion by having an AggregateResourceBundleLoader and calling a loadResourceBundle in the loadResourceBundle method and the AggregateResourceBundleLoader will end up calling it again and it goes on and on and we get a StackOverFlowError at the end.

      Changeing the class like this solved the problem:

      @Component(
          immediate = true,
          property = {
             "bundle.symbolic.name=com.liferay.blogs.web",
             "resource.bundle.base.name=content.Language",
             "servlet.context.name=blogs-web"
          }
      )
      public class LhcLoginModuleResourceBundleLoader implements ResourceBundleLoader {
      
      	@Override
      	public ResourceBundle loadResourceBundle(Locale locale) {
      		return _resourceBundleLoader.loadResourceBundle(locale);
      	}
      
      	@Reference(
      		target = "(&(bundle.symbolic.name=com.liferay.login.web)(!(component.name=com.lhcargo.eportal.modules.resource.bundle.LhcLoginModuleResourceBundleLoader)))"
      	)
      	public void setResourceBundleLoader(
      		ResourceBundleLoader resourceBundleLoader) {
      
      		_resourceBundleLoader =
      				new ClassResourceBundleLoader(
      					"content.Language",
      					LhcLoginModuleResourceBundleLoader.class.getClassLoader());
      	}
      
      	private ClassResourceBundleLoader _resourceBundleLoader;
      
      }
      

      Related tickets:
      LPP-32932
      https://liferay-support.zendesk.com/agent/tickets/3532

       

      Both CE and EE docs will need to be updated:

      https://dev.liferay.com/hu/develop/tutorials/-/knowledge_base/7-1/overriding-a-modules-language-keys

       

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Packages

                Version Package
                7.0.x
                7.1.x