Ed Schaller created FELIX-3547:
----------------------------------

             Summary: NPE in httplite on android creating Locale.
                 Key: FELIX-3547
                 URL: https://issues.apache.org/jira/browse/FELIX-3547
             Project: Felix
          Issue Type: Bug
          Components: Lightweight HTTP Service
         Environment: Android 2.3.x
            Reporter: Ed Schaller


httplite/core/src/main/java/org/apache/felix/httplite/servlet/HttpServletRequestImpl.java
 contains the following at line 86:

private final Locale m_locale = new Locale( System.getProperty( "user.language" 
), System.getProperty( "user.country" ) );

On Android (at least 2.3, other versions not tried) this produces a 
NullPointerException when HttpServletRequestImpl is constructed because the 
Locale constructor cannot handle null and neither property is defined by 
default on Android.

This is trivial to work around with code like:

if(System.getProperty("user.language")==null)
        System.setProperty("user.language", Locale.getDefault().getLanguage());
if(System.getProperty("user.country")==null)
        System.setProperty("user.country", Locale.getDefault().getCountry());

A easy solution is to replace the above line with:

private final Locale m_locale = Locale.getDefault();

This would cause each instance to have the same Local object. Although I would 
be surprised if this is an issue the following would also work:

private final Locale m_locale = new Locale( System.getProperty( 
"user.language", Locale.getDefault().getLanguage() ), System.getProperty( 
"user.country" ) , Locale.getDefault().getCountry());

I'm using httplite with the felx web console for debugging. Other than this bug 
and needing to set an uncaught exception handler so android doesn't force close 
the app all is working well (the memory usage plugin of coarse dose not work 
because it depends on jmx which android doesn't have.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to