sebb        2005/01/08 07:10:41

  Modified:    src/core/org/apache/jmeter/resources Tag: rel-2_0
                        PackageTest.java
  Log:
  Add check for possibly incorrectly formatted messages (see bug 32993)
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.8.2.4   +26 -5     
jakarta-jmeter/src/core/org/apache/jmeter/resources/PackageTest.java
  
  Index: PackageTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/resources/PackageTest.java,v
  retrieving revision 1.8.2.3
  retrieving revision 1.8.2.4
  diff -u -r1.8.2.3 -r1.8.2.4
  --- PackageTest.java  30 Oct 2004 10:24:06 -0000      1.8.2.3
  +++ PackageTest.java  8 Jan 2005 15:10:41 -0000       1.8.2.4
  @@ -67,9 +67,11 @@
        return new PropertyResourceBundle(ras);
       }
   
  +    private static Object [] DUMMY_PARAMS = new 
Object[]{"1","2","3","4","5","6","7","8","9"}; 
       //       Read resource file saving the keys
  -    private void readRF(String res, List l) throws Exception
  +    private int readRF(String res, List l) throws Exception
       {
  +     int fails =0 ;
                InputStream ras = this.getClass().getResourceAsStream(res);
                BufferedReader fileReader =
                new BufferedReader(new InputStreamReader(ras));
  @@ -77,9 +79,28 @@
           while((s=fileReader.readLine())!=null)
           {
                if (s.length() > 0 && !s.startsWith("#"))  {
  -                     l.add(s.substring(0,s.indexOf('=')));
  +                     l.add(s.substring(0,s.indexOf('='))); // Store the key
  +                     /*
  +                      *  Now check for invalid message format:
  +                      *  if string contains {0} and ' there may  be a 
problem,
  +                      *  so do a format with dummy parameters and check if 
there
  +                      *  is a { in the output.
  +                      *  A bit crude, but should be enough for now.
  +                      */
  +                     if (s.indexOf("{0}") > 0 && s.indexOf("'") > 0)
  +                     {
  +                             String m = 
java.text.MessageFormat.format(s,DUMMY_PARAMS);
  +                             if (m.indexOf("{") > 0) {
  +                                     fails++;
  +                                     System.out.println("Incorrect message 
format ? (input/output): ");
  +                                 System.out.println(s);
  +                                 System.out.println(m);
  +                             }
  +                     }
  +
                }
                } 
  +        return fails;
       }
       
       // Helper method to construct resource name
  @@ -103,7 +124,7 @@
        {
                ArrayList alf = new ArrayList(500);// holds keys from file
                String res = getResName(resname);
  -             readRF(res,alf);
  +             subTestFailures += readRF(res,alf);
                Collections.sort(alf);
                
                // Look for duplicate keys in the file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to