Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-3783 - Avoid using non-threadsafe XPath as static property #3906

Merged
merged 2 commits into from Apr 30, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Avoid using non-threadsafe XPath as static instance

  • Loading branch information...
svendiedrichsen committed Apr 17, 2019
commit 579205ca041d1c65650ca8d4ff17400d85d102f9
@@ -100,62 +100,59 @@
*/
abstract class CombinedXPath {

private static final Logger logger = Logger.getLogger(JavaWebStartInfo.APPCLIENT_SERVER_MAIN_LOGGER,
private static final Logger logger = Logger.getLogger(JavaWebStartInfo.APPCLIENT_SERVER_MAIN_LOGGER,
JavaWebStartInfo.APPCLIENT_SERVER_LOGMESSAGE_RESOURCE);

/** property names for the types of combined JNLP content */
private static final String OWNED_PROPERTY_NAME = "owned";
private static final String DEFAULTED_PROPERTY_NAME = "defaulted";
private static final String MERGED_PROPERTY_NAME = "merged";

private final static XPathFactory xPathFactory = XPathFactory.newInstance();

private final static XPath xPath = xPathFactory.newXPath();
private final static XPathFactory xPathFactory = XPathFactory.newInstance();

private static LSSerializer lsSerializer = null;
private static LSOutput lsOutput = null;

private final String parentPath;
private final String targetRelativePath;

/** xpath expression for the target node in the DOM for the developer's XML */
private final XPathExpression targetExpr;

/** if developer didn't provide the target, this is the parent where we'll
* create a new child.
*/
private final XPathExpression parentExpr;

private static enum Type {
private enum Type {
OWNED(OWNED_PROPERTY_NAME) {
CombinedXPath combinedXPath(String pathA, String pathB) {
return new OwnedXPath(xPath, pathA, pathB);
return new OwnedXPath(xPathFactory.newXPath(), pathA, pathB);
}
},
DEFAULTED(DEFAULTED_PROPERTY_NAME) {
CombinedXPath combinedXPath(String pathA, String pathB) {
return new DefaultedXPath(xPath, pathA, pathB);
return new DefaultedXPath(xPathFactory.newXPath(), pathA, pathB);
}
},
MERGED(MERGED_PROPERTY_NAME) {
CombinedXPath combinedXPath(String pathA, String pathB) {
return new MergedXPath(xPath, pathA, pathB);
return new MergedXPath(xPathFactory.newXPath(), pathA, pathB);
}
};

private String propertyName;

Type(final String propName) {
propertyName = propName;
}

abstract CombinedXPath combinedXPath(String pathA, String pathB);

}

static List<CombinedXPath> parse(final Properties p) {
List<CombinedXPath> result = new ArrayList<CombinedXPath>();
// result.addAll(CombinedXPath.parse(p, CombinedXPath.Type.OWNED));
List<CombinedXPath> result = new ArrayList<>();
result.addAll(CombinedXPath.parse(p, CombinedXPath.Type.DEFAULTED));
result.addAll(CombinedXPath.parse(p, CombinedXPath.Type.MERGED));
return result;
@@ -173,12 +170,12 @@ CombinedXPath combinedXPath(String pathA, String pathB) {
private static List<CombinedXPath> parse(
final Properties p,
Type type) {

final List<CombinedXPath> result = new
ArrayList<CombinedXPath>();
ArrayList<>();
final String refs = p.getProperty(type.propertyName);
for (String ref : refs.split(",")) {
final String paths[] = ref.split(":");
final String[] paths = ref.split(":");
if (paths.length != 2) {
throw new IllegalArgumentException(ref);
}
@@ -189,7 +186,7 @@ CombinedXPath combinedXPath(String pathA, String pathB) {

/**
* Creates a new combined XPath.
*
*
* @param xPath XPath available for searching
* @param parentPath path to parent for new child (if developer's document lacks the target)
* @param targetRelativePath path relative to the parent for the target node in the developer DOM
@@ -324,7 +321,7 @@ void process(Document developerDOM, Document generatedDOM) throws XPathExpressio
}
}
}

}

/**
@@ -40,11 +40,8 @@

package org.glassfish.appclient.server.core.jws;

import com.sun.logging.LogDomains;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLConnection;
@@ -54,7 +51,6 @@
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import org.glassfish.api.deployment.archive.ReadableArchive;
@@ -64,7 +60,6 @@
import org.glassfish.appclient.server.core.StandaloneAppClientDeployerHelper;
import org.glassfish.appclient.server.core.jws.servedcontent.Content;
import org.glassfish.appclient.server.core.jws.servedcontent.DynamicContent;
import org.glassfish.appclient.server.core.jws.servedcontent.FixedContent;
import org.glassfish.appclient.server.core.jws.servedcontent.SimpleDynamicContentImpl;
import org.glassfish.appclient.server.core.jws.servedcontent.StaticContent;
import org.glassfish.logging.annotation.LogMessageInfo;
@@ -86,10 +81,8 @@

private final static XPathFactory xPathFactory = XPathFactory.newInstance();

private final static XPath xPath = xPathFactory.newXPath();

private static final Logger logger = Logger.getLogger(JavaWebStartInfo.APPCLIENT_SERVER_MAIN_LOGGER, JavaWebStartInfo.APPCLIENT_SERVER_LOGMESSAGE_RESOURCE);

@LogMessageInfo (
message = "Client JNLP document {0} refers to the static resource {1} that does not exist or is not readable.",
cause = "The developer-provided JNLP content refers to a file as if the file is in the application but the server could not find the file.",
@@ -101,7 +94,7 @@
cause = "During deployment of nested app clients (those inside EARs), the system should use an ApplicationSignedJARManager but it is null.",
action = "This is a system error. Please report this as a bug.")
public static final String SIGNED_JAR_MGR_NULL = "AS-ACDEPL-00114";

@LogMessageInfo(
message = "Tbe custom JNLP document {0} in a stand-alone app client incorrectly refers to a JAR {1}",
cause = "The app client includes a custom JNLP document which refers to a JAR. Stand-alone app clients cannot refer to other JARs because they are self-contained deployment units.",
@@ -122,7 +115,7 @@
private XPathToDeveloperProvidedContentRefs(final String path) {
super();
try {
xPathExpr = xPath.compile(path);
xPathExpr = xPathFactory.newXPath().compile(path);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -137,7 +130,7 @@ private XPathToDeveloperProvidedContentRefs(final String path) {
parse(p, XPathToDeveloperProvidedContentRefs.Type.DYNAMIC));
return result;
}

/**
* Extracts the relevant information from the Properties object and
* creates the correct set of content objects depending on which type
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.