[MAGNOLIA-5635] i18n message bundle resolver cannot handle identical named files Created: 23/Jan/14  Updated: 16/Sep/15  Resolved: 03/Jun/14

Status: Closed
Project: Magnolia
Component/s: i18n
Affects Version/s: 5.2.1
Fix Version/s: 5.2.6, 5.3

Type: Bug Priority: Major
Reporter: David Nyffenegger Assignee: Federico Grilli
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to MAGNOLIA-6376 ClasspathResourceOrigin should warn u... Open
causality
is causing MAGNOLIA-5823 i18n message bundles that contain UTF... Closed
dependency
depends upon MAGNOLIA-5802 Update version of commons-io Closed
duplicate
is duplicated by MAGNOLIA-5430 i18nsystem: if property files have sa... Closed
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

Assume two or more modules have a message bundle with the same name in their /mgnl-i18n/ directory. The current message bundle resolvers loads just one of them - all other are silently ignored.
Java supports resolving multiple resources with the same name on the classpath by providing the ClassLoader.getResources method.

Please consider using this method or fixing it up otherwise. The current implementation is dangerous.

Workaround: add prefixes to the message bundles and hope, that no other module uses the same prefix/name.



 Comments   
Comment by David Nyffenegger [ 23/Jan/14 ]

A patch could look like that:

In info.magnolia.cms.util.ClasspathResourcesUtil add a method getResources:

info.magnolia.cms.util.ClasspathResourcesUtil
    /**
     * Get the resource using the current class loader. The leading / is removed as the call to class.getResource()
     * would do.
     * @param name
     * @return the resource
     */
    public static Enumeration<URL> getResources(String name) {
        return getCurrentClassLoader().getResources(StringUtils.removeStart(name, "/"));
    }

In the method loadMessages of info.magnolia.i18nsystem.DefaultMessageBundlesLoader use this new method instead the getStream method and iterate over the returned urls for loading the message bundles.

Comment by Daniel Lipp [ 03/Jun/14 ]

Reopening for two reasons:
a) it causing a build failure because coverage dropped under the threshold - looks like there's not a single unit-test for the whole DefaultMessageBundlesLoader
b) it hasn't been ported to 5.2.x branch

Generated at Mon Feb 12 04:06:58 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.