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: 26/Apr/06 01:51 AM   Updated: 04/Jul/07 03:36 AM
Return to search
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 12:01 PM Niall Pemberton 0.9 kB
Environment:
Operating System: other
Platform: Other

Bugzilla 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
Repository Revision Date User Message
Struts #397770 Fri Apr 28 05:43:44 UTC 2006 mrdon Adding warning if resource didn't load correctly
STR-2843
Files Changed
MODIFY /struts/action/trunk/core/src/main/java/org/apache/struts/util/PropertyMessageResources.java