You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2019/05/21 07:45:38 UTC
svn commit: r1859613 -
/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java
Author: pmouawad
Date: Tue May 21 07:45:38 2019
New Revision: 1859613
URL: http://svn.apache.org/viewvc?rev=1859613&view=rev
Log:
Fix sonar errors
Use XMLInputFactory.newInstance instead of XMLInputFactory.newFactory as they have same meaning and code, but latest method does not exist in stax
Modified:
jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java
Modified: jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java?rev=1859613&r1=1859612&r2=1859613&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java (original)
+++ jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java Tue May 21 07:45:38 2019
@@ -48,7 +48,7 @@ class ObjectMessageRenderer implements M
if (hasVariable) {
value = getInterpretedContent(filename, encoding, hasVariable, cache);
} else {
- value = (Serializable) cache.get(filename, _p -> getContent(filename));
+ value = (Serializable) cache.get(filename, p -> getContent(filename));
}
return value;
@@ -76,27 +76,26 @@ class ObjectMessageRenderer implements M
/**
* <p>Gets content with variable replaced.</p>
- * <p>If encoding {@link PublisherSampler#DEFAULT_ENCODING isn't provided}, try to find it.</p>
+ * <p>If pEncoding {@link PublisherSampler#DEFAULT_ENCODING isn't provided}, try to find it.</p>
* <p>Only raw text is cached, neither interpreted text, neither parsed object.</p>
*/
- protected Serializable getInterpretedContent(String filename, String encoding, boolean hasVariable, Cache<Object,Object> cache) {
- Serializable value;
+ protected Serializable getInterpretedContent(String filename, final String pEncoding, boolean hasVariable, Cache<Object,Object> cache) {
+ String encoding = pEncoding;
if (PublisherSampler.DEFAULT_ENCODING.equals(encoding)) {
encoding = findEncoding(filename);
}
String stringValue = delegate.getValueFromFile(filename, encoding, hasVariable, cache);
- value = (Serializable) JMeterUtils.createXStream().fromXML(stringValue);
- return value;
+ return (Serializable) JMeterUtils.createXStream().fromXML(stringValue);
}
/** Try to determine encoding based on XML prolog, if none <code>null</code> is returned. **/
protected String findEncoding(String filename) {
- XMLInputFactory factory = XMLInputFactory.newFactory();
+ XMLInputFactory factory = XMLInputFactory.newInstance();
try (FileInputStream input = new FileInputStream(filename)) {
XMLStreamReader reader = factory.createXMLStreamReader(input);
return reader.getEncoding();
} catch (IOException|XMLStreamException e) {
- throw new RuntimeException(format("Unable to read %s", filename), e);
+ throw new IllegalArgumentException(format("Unable to read %s", filename), e);
}
}
Re: svn commit: r1859613 -
/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java
Posted by Felix Schumacher <fe...@internetallee.de>.
Am 21.05.19 um 09:45 schrieb pmouawad@apache.org:
> Author: pmouawad
> Date: Tue May 21 07:45:38 2019
> New Revision: 1859613
>
> URL: http://svn.apache.org/viewvc?rev=1859613&view=rev
> Log:
> Fix sonar errors
> Use XMLInputFactory.newInstance instead of XMLInputFactory.newFactory as they have same meaning and code, but latest method does not exist in stax
In the javadocs for XMLInputFactory
(https://docs.oracle.com/javase/8/docs/api/javax/xml/stream/XMLInputFactory.html#newFactory--)
it states, that newInstance is deprecated.
But looking at newInstance in the same docs, the method is not marked as
deprecated. Strange.
>
> Modified:
> jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java
>
> Modified: jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java
> URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java?rev=1859613&r1=1859612&r2=1859613&view=diff
> ==============================================================================
> --- jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java (original)
> +++ jmeter/trunk/src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/render/ObjectMessageRenderer.java Tue May 21 07:45:38 2019
> @@ -48,7 +48,7 @@ class ObjectMessageRenderer implements M
> if (hasVariable) {
> value = getInterpretedContent(filename, encoding, hasVariable, cache);
> } else {
> - value = (Serializable) cache.get(filename, _p -> getContent(filename));
> + value = (Serializable) cache.get(filename, p -> getContent(filename));
> }
>
> return value;
> @@ -76,27 +76,26 @@ class ObjectMessageRenderer implements M
>
> /**
> * <p>Gets content with variable replaced.</p>
> - * <p>If encoding {@link PublisherSampler#DEFAULT_ENCODING isn't provided}, try to find it.</p>
> + * <p>If pEncoding {@link PublisherSampler#DEFAULT_ENCODING isn't provided}, try to find it.</p>
Is this renamed parameter more readable?
> * <p>Only raw text is cached, neither interpreted text, neither parsed object.</p>
> */
> - protected Serializable getInterpretedContent(String filename, String encoding, boolean hasVariable, Cache<Object,Object> cache) {
> - Serializable value;
> + protected Serializable getInterpretedContent(String filename, final String pEncoding, boolean hasVariable, Cache<Object,Object> cache) {
> + String encoding = pEncoding;
> if (PublisherSampler.DEFAULT_ENCODING.equals(encoding)) {
> encoding = findEncoding(filename);
> }
> String stringValue = delegate.getValueFromFile(filename, encoding, hasVariable, cache);
> - value = (Serializable) JMeterUtils.createXStream().fromXML(stringValue);
> - return value;
> + return (Serializable) JMeterUtils.createXStream().fromXML(stringValue);
> }
>
> /** Try to determine encoding based on XML prolog, if none <code>null</code> is returned. **/
> protected String findEncoding(String filename) {
> - XMLInputFactory factory = XMLInputFactory.newFactory();
> + XMLInputFactory factory = XMLInputFactory.newInstance();
Should we push the creation of the factory outside to a field? I
remember, that the creation of such an object is quite expensive and I
believe it should be thread safe, if we are only calling
createXMLStreamReader on it.
> try (FileInputStream input = new FileInputStream(filename)) {
> XMLStreamReader reader = factory.createXMLStreamReader(input);
> return reader.getEncoding();
Do we have to close reader here?
Felix
> } catch (IOException|XMLStreamException e) {
> - throw new RuntimeException(format("Unable to read %s", filename), e);
> + throw new IllegalArgumentException(format("Unable to read %s", filename), e);
> }
> }
>
>
>