History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: STR-2843
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Don Brown
Reporter: qxo
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Struts 1

PropertyMessageResources.loadLocale(String localeKey) has a problem!

Created: 25/Apr/06 06:51 PM   Updated: 03/Jul/07 08:36 PM
Component/s: Core
Affects Version/s: Nightly Build
Fix Version/s: 1.3.3

File Attachments:
  Size
Text File Licensed for inclusion in ASF works struts-STR-1843.patch 2006-04-27 05:01 AM Niall Pemberton 0.9 kb
Environment:
Operating System: other
Platform: Other

Bugzilla Id: http://issues.apache.org/bugzilla/show_bug.cgi?id=35155


 Description  « Hide
when
struts-config.xml -->message-resources -->parameter:resourceA
if resourceA not existed,it should show some error message,but not!

cause:
  PropertyMessageResources.loadLocale(String localeKey) has a problem!
I fixed it;
Code:


        protected synchronized void loadLocale(String localeKey) {

            // Have we already attempted to load messages for this locale?
            if (locales.get(localeKey) != null) {
                return;
            }
            
            if (log.isTraceEnabled()) {
                log.trace("loadLocale(" + localeKey + ")");
            }
            
        
            
            locales.put(localeKey, localeKey);

            // Set up to load the property resource for this locale key, if we can
            String name = config.replace('.', '/');
            if (localeKey.length() > 0) {
                name += "_" + localeKey;
            }
            
            name += ".properties";
            InputStream is = null;
          
            // Load the specified property resource
            if (log.isTraceEnabled()) {
                log.trace(" Loading resource '" + name + "'");
            }
            
            ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
            if (classLoader == null) {
                classLoader = this.getClass().getClassLoader();
            }
            
            is = classLoader.getResourceAsStream(name);
            if (is != null) {
                Properties props = new Properties();
    
                try {
                    props.load(is);
                } catch (IOException e) {
                    log.error("loadLocale()", e);
                } finally {
                    try {
                        is.close();
                    } catch (IOException e) {
                        log.error("loadLocale()", e);
                    }
                }
                
                // Copy the corresponding values into our cache
                if (props.size() < 1) {
                    return;
                }
                
                synchronized (messages) {
                    Iterator names = props.keySet().iterator();
                    while (names.hasNext()) {
                        String key = (String) names.next();
                        if (log.isTraceEnabled()) {
                            log.trace(" Saving message key '" +
messageKey(localeKey, key));
                        }
                        messages.put(messageKey(localeKey, key),
props.getProperty(key));
                    }
                }
                if (log.isTraceEnabled()) {
                    log.trace(" Loading resource completed");
                }
            }else{
                
                if (log.isWarnEnabled()) {
                    log.warn("the resource not found.");
                }
            }
        }

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Don Brown - 25/Apr/06 06:52 PM
Had to clone due to corrupted ticket

Niall Pemberton - 27/Apr/06 05:01 AM
From a scan of the method posted by the reporter looks like the change simply logs a warning if the resource is not found. Attached patch is slightly different in implementation of the same.

Don Brown - 28/Apr/06 05:44 AM
Um, Niall, you know you are a committer and can commit your own damn patches... ;)

Thanks qxo for the patch!