Code review request: 7068662 Reserve and restore the default locale

Xuelei Fan xuelei.fan at oracle.com
Thu Jul 21 06:46:30 PDT 2011


On 7/21/2011 5:14 PM, Chris Hegarty wrote:
> 
> On 07/21/11 09:02 AM, Xuelei Fan wrote:
>> ....
>>> I see you've updated
>>> test/java/net/URLConnection/SetIfModifiedSince.java. I'm not sure if I'm
>>> reading that test correctly but it looks like it will pass even if there
>>> is a problem.
>>>
>> There is no problem to pass the test. The problem is that it changes the
>> default locale to Locale.JAPAN, as may impact the following test cases.
> 
> I think what Alan is getting at there is that the test will never fail,
> even if the bug exists. This is because the test throws RuntimeException
> from a thread other than the main thread. This problem is not related to
> your changes, just an observation I guess.
> 
You are right. I did not look into the logic of the test.

> You can fix it while you're making changes in this area, or I can file a
> separate CR for this.
> 
Would you please fill a new CR for this? So that this CR will only focus
on locale issues.

Thanks,
Xuelei

> To resolve the problem we will need to set an error condition when
> failure is detected and probably easiest to block the main thread until
> the server thread completes, server.join(). The sleeps can also be removed.
> 
> hg diff SetIfModifiedSince.java
> diff -r 8bbea505b060 test/java/net/URLConnection/SetIfModifiedSince.java
> --- a/test/java/net/URLConnection/SetIfModifiedSince.java       Mon Jul
> 18 22:25:58 2011 +0100
> +++ b/test/java/net/URLConnection/SetIfModifiedSince.java       Thu Jul
> 21 10:11:13 2011 +0100
> @@ -32,42 +32,35 @@ import java.util.*;
>  import java.util.*;
> 
>  public class SetIfModifiedSince {
> +    static volatile boolean failed;
> 
>      static class XServer extends Thread {
>          ServerSocket srv;
> -        Socket s;
> -        InputStream is;
> -        OutputStream os;
> 
>          XServer (ServerSocket s) {
>              srv = s;
>          }
> 
> -        Socket getSocket () {
> -            return (s);
> -        }
> -
>          public void run() {
>              try {
>                  String x;
> -                s = srv.accept ();
> -                is = s.getInputStream ();
> -                BufferedReader r = new BufferedReader(new
> InputStreamReader(is));
> -                os = s.getOutputStream ();
> -                while ((x=r.readLine()) != null) {
> -                    String header = "If-Modified-Since: ";
> -                    if (x.startsWith(header)) {
> -                        if (x.charAt(header.length()) == '?') {
> -                            s.close ();
> -                            srv.close (); // or else the
> HTTPURLConnection will retry
> -                            throw new RuntimeException
> -                                    ("Invalid HTTP date specification");
> +                Socket s = srv.accept ();
> +                srv.close (); // or else the HTTPURLConnection will retry
> +
> +                try (BufferedReader r = new BufferedReader(new
> InputStreamReader(s.getInputStream()));
> +                     OutputStream os = s.getOutputStream()) {
> +
> +                    while ((x=r.readLine()) != null) {
> +                        String header = "If-Modified-Since: ";
> +                        if (x.startsWith(header)) {
> +                            if (x.charAt(header.length()) == '?') {
> +                                failed = true;
> +                            }
> +                            break;
>                          }
> -                        break;
>                      }
> +                    s.close ();
>                  }
> -                s.close ();
> -                srv.close (); // or else the HTTPURLConnection will retry
>              } catch (IOException e) {}
>          }
>      }
> @@ -79,14 +72,15 @@ public class SetIfModifiedSince {
>              int port = serversocket.getLocalPort ();
>              XServer server = new XServer (serversocket);
>              server.start ();
> -            Thread.sleep (2000);
>              URL url = new URL ("http://localhost:"+port+"/index.html");
>              URLConnection urlc = url.openConnection ();
>              urlc.setIfModifiedSince (10000000);
>              InputStream is = urlc.getInputStream ();
> -            int i=0, c;
> -            Thread.sleep (5000);
> -        } catch (Exception e) {
> +            server.join();
> +        } catch (Exception e) { }
> +
> +        if (failed) {
> +            throw new RuntimeException("Invalid HTTP date specification");
>          }
>      }
>  }
> 
> 
> -Chris.
> 
>>> Minor nit in test/sun/util/resources/Locale/Bug4965260.java and
>>> test/sun/util/resources/TimeZone/Bug4640234.java is that they are using
>>> 2 space indenting whereas we use 4 spaces in java code.
>>>
>> Tidied up.
>>
>> Thanks,
>> Xuelei
>>
>>> -Alan.
>>>
>>



More information about the jdk8-dev mailing list