You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by sebb <se...@gmail.com> on 2017/03/17 15:05:04 UTC

Re: svn commit: r1787308 - /jmeter/trunk/src/core/org/apache/jmeter/util/JSR223BeanInfoSupport.java

On 17 March 2017 at 09:36,  <pm...@apache.org> wrote:
> Author: pmouawad
> Date: Fri Mar 17 09:36:53 2017
> New Revision: 1787308
>
> URL: http://svn.apache.org/viewvc?rev=1787308&view=rev
> Log:
> Bug 60874 - Backward incompatibility introduced in WebDriver Sampler in JMeter 3.2
> Bugzilla Id: 60874
>
> Modified:
>     jmeter/trunk/src/core/org/apache/jmeter/util/JSR223BeanInfoSupport.java

Good solution.

> Modified: jmeter/trunk/src/core/org/apache/jmeter/util/JSR223BeanInfoSupport.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/JSR223BeanInfoSupport.java?rev=1787308&r1=1787307&r2=1787308&view=diff
> ==============================================================================
> --- jmeter/trunk/src/core/org/apache/jmeter/util/JSR223BeanInfoSupport.java (original)
> +++ jmeter/trunk/src/core/org/apache/jmeter/util/JSR223BeanInfoSupport.java Fri Mar 17 09:36:53 2017
> @@ -38,7 +38,14 @@ public abstract class JSR223BeanInfoSupp
>
>      private static final String[] LANGUAGE_TAGS;
>
> -    private static final String[][] LANGUAGE_NAMES;
> +    /**
> +     * Will be removed in next version following 3.2
> +     * @deprecated use {@link JSR223BeanInfoSupport#getLanguageNames()}
> +     */
> +    @Deprecated
> +    public static final String[][] LANGUAGE_NAMES; // NOSONAR Kept for backward compatibility
> +
> +    private static final String[][] CONSTANT_LANGUAGE_NAMES;
>
>      static {
>          Map<String, ScriptEngineFactory> nameMap = new HashMap<>();
> @@ -52,30 +59,39 @@ public abstract class JSR223BeanInfoSupp
>          }
>          LANGUAGE_TAGS = nameMap.keySet().toArray(new String[nameMap.size()]);
>          Arrays.sort(LANGUAGE_TAGS);
> -        LANGUAGE_NAMES = new String[nameMap.size()][2];
> +        CONSTANT_LANGUAGE_NAMES = new String[nameMap.size()][2];
>          int i = 0;
>          for(Entry<String, ScriptEngineFactory> me : nameMap.entrySet()) {
>              final String key = me.getKey();
> -            LANGUAGE_NAMES[i][0] = key;
> +            CONSTANT_LANGUAGE_NAMES[i][0] = key;
>              final ScriptEngineFactory fact = me.getValue();
> -            LANGUAGE_NAMES[i++][1] = key +
> +            CONSTANT_LANGUAGE_NAMES[i++][1] = key +
>                      "     (" // $NON-NLS-1$
>                      + fact.getLanguageName() + " " + fact.getLanguageVersion()  // $NON-NLS-1$
>                      + " / "  // $NON-NLS-1$
>                      + fact.getEngineName() + " " + fact.getEngineVersion() // $NON-NLS-1$
>                      + ")";   // $NON-NLS-1$
>          }
> +
> +        LANGUAGE_NAMES = getLanguageNames();
>      }
>
>      private static final ResourceBundle NAME_BUNDLE = new ListResourceBundle() {
>          @Override
>          protected Object[][] getContents() {
> -            return LANGUAGE_NAMES;
> +            return CONSTANT_LANGUAGE_NAMES;

Just wonder whether this should be cloned?
Probably OK without clone as it only gets passed to JMeter code.


>          }
>      };
>
>      protected JSR223BeanInfoSupport(Class<? extends TestBean> beanClass) {
>          super(beanClass, LANGUAGE_TAGS, NAME_BUNDLE);
>      }
> +
> +    /**
> +     * @return String array of 2 columns array containing Script engine short name / Script Language details
> +     */
> +    public static final String[][] getLanguageNames() {
> +        return CONSTANT_LANGUAGE_NAMES.clone();

+1
This definitely needs to use clone otherwise no point in making the
array private!

> +    }
>
>  }
>
>