[Mulgara-svn] r2028 - in trunk/src/jar: query/java/org/mulgara/server querylang/java/org/mulgara/itql querylang/java/org/mulgara/protocol/http resolver/java/org/mulgara/resolver resolver-memory/java/org/mulgara/resolver/memory server/java/org/mulgara/server tuples/java/org/mulgara/store/tuples util/java/org/mulgara/util web/java/org/mulgara/webquery
pag at mulgara.org
pag at mulgara.org
Thu Sep 15 01:56:10 UTC 2011
Author: pag
Date: 2011-09-15 01:56:09 +0000 (Thu, 15 Sep 2011)
New Revision: 2028
Modified:
trunk/src/jar/query/java/org/mulgara/server/SessionFactoryFactory.java
trunk/src/jar/querylang/java/org/mulgara/itql/ItqlSession.java
trunk/src/jar/querylang/java/org/mulgara/itql/TqlSession.java
trunk/src/jar/querylang/java/org/mulgara/protocol/http/MimeMultiNamedPart.java
trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java
trunk/src/jar/querylang/java/org/mulgara/protocol/http/TqlServlet.java
trunk/src/jar/resolver-memory/java/org/mulgara/resolver/memory/Stating.java
trunk/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java
trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java
trunk/src/jar/tuples/java/org/mulgara/store/tuples/UnboundJoin.java
trunk/src/jar/util/java/org/mulgara/util/ObjectUtil.java
trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java
trunk/src/jar/web/java/org/mulgara/webquery/ResourceFile.java
Log:
Fortify updates
Modified: trunk/src/jar/query/java/org/mulgara/server/SessionFactoryFactory.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/server/SessionFactoryFactory.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/query/java/org/mulgara/server/SessionFactoryFactory.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -38,6 +38,7 @@
import org.mulgara.config.MulgaraConfig;
import org.mulgara.server.SessionFactory;
import org.mulgara.util.ClasspathDesc;
+import org.mulgara.util.ObjectUtil;
import java.lang.reflect.Constructor;
@@ -92,7 +93,7 @@
URL defaultConfigURL = ClassLoader.getSystemResource(CONFIG_PATH);
if (defaultConfigURL == null) {
- defaultConfigURL = this.getClass().getClassLoader().getResource(CONFIG_PATH);
+ defaultConfigURL = ObjectUtil.getClassLoader(this).getResource(CONFIG_PATH);
if (defaultConfigURL == null) {
throw new SessionFactoryException(
Modified: trunk/src/jar/querylang/java/org/mulgara/itql/ItqlSession.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/itql/ItqlSession.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/querylang/java/org/mulgara/itql/ItqlSession.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -523,7 +523,7 @@
URL scriptURL = null;
// find the current directory
- String currentDirectory = System.getProperty("user.dir");
+ String currentDirectory = System.getProperty("user.dir", ".");
// append a "/" if we need to
if (!currentDirectory.endsWith("/")) {
Modified: trunk/src/jar/querylang/java/org/mulgara/itql/TqlSession.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/itql/TqlSession.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/querylang/java/org/mulgara/itql/TqlSession.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -579,7 +579,7 @@
URL scriptUrl = null;
// find the current directory
- String currentDirectory = System.getProperty(USER_DIR);
+ String currentDirectory = System.getProperty(USER_DIR, ".");
// append a "/" if we need to
if (!currentDirectory.endsWith("/")) currentDirectory += File.separator;
Modified: trunk/src/jar/querylang/java/org/mulgara/protocol/http/MimeMultiNamedPart.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/protocol/http/MimeMultiNamedPart.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/querylang/java/org/mulgara/protocol/http/MimeMultiNamedPart.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -155,13 +155,14 @@
}
o = sb;
} catch (IOException e) {
- o = null;
+ return null;
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // got our data at this point, so ignore
+ }
}
- try {
- in.close();
- } catch (IOException e) {
- // got our data at this point, so ignore
- }
}
return o.toString();
}
Modified: trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/querylang/java/org/mulgara/protocol/http/ProtocolServlet.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -877,6 +877,7 @@
String p = getParam(PREDICATE_PARAM_NAMES, params);
String o = getParam(OBJECT_PARAM_NAMES, params);
if (s == null && p == null && o == null) return new Pair<URI,LocalTriple>(g, null);
+ if (s == null || p == null || o == null) throw new BadRequestException("Incomplete triple specified");
return new Pair<URI,LocalTriple>(g, new LocalTriple(s, p, o, true));
}
Modified: trunk/src/jar/querylang/java/org/mulgara/protocol/http/TqlServlet.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/protocol/http/TqlServlet.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/querylang/java/org/mulgara/protocol/http/TqlServlet.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -169,8 +169,13 @@
}
}
}
- output.addDocFooter();
- output.close();
+ if (output == null) {
+ OutputStream s = resp.getOutputStream();
+ if (s != null) s.close();
+ } else {
+ output.addDocFooter();
+ output.close();
+ }
}
}
@@ -218,8 +223,13 @@
}
}
}
- output.addDocFooter();
- output.close();
+ if (output == null) {
+ OutputStream s = resp.getOutputStream();
+ if (s != null) s.close();
+ } else {
+ output.addDocFooter();
+ output.close();
+ }
}
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/RestoreOperation.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -165,7 +165,7 @@
) throws Exception {
// Check the header of the backup file.
String line = br.readLine();
- if (!line.startsWith(BACKUP_FILE_HEADER)) {
+ if (line == null || !line.startsWith(BACKUP_FILE_HEADER)) {
throw new QueryException("Not a backup file");
}
String versionString = line.substring(BACKUP_FILE_HEADER.length());
@@ -193,7 +193,6 @@
* @param metadata DatabaseMetadata
* @param br BufferedReader
*/
- @SuppressWarnings("unchecked")
private void restoreDatabaseV4(
Resolver resolver, ResolverSession resolverSession,
DatabaseMetadata metadata, BufferedReader br
@@ -209,6 +208,7 @@
String line;
do {
line = br.readLine();
+ if (line == null) throw new QueryException("Unexpected EOF in header section while restoring from backup file: " + sourceURI);
} while (!line.equals("RDFNODES"));
// Remove all statements from store except those reserving
@@ -338,7 +338,7 @@
LongBuffer tripleBuffer = buffer.asLongBuffer();
// Maps from a group (Long) to a Set of models (Set of Longs).
- Map g2mMap = new HashMap();
+ Map<Long,Set<Long>> g2mMap = new HashMap<Long,Set<Long>>();
for (;;) {
try {
@@ -379,10 +379,10 @@
// Set up a mapping from each V4 Group node to (multiple) Graph
// nodes.
Long groupL = new Long(node0);
- Set modelSet = (Set)g2mMap.get(groupL);
+ Set<Long> modelSet = g2mMap.get(groupL);
if (modelSet == null) {
assert n2nMap.getLong(node0) == BackupRestoreSession.NONE;
- modelSet = new HashSet();
+ modelSet = new HashSet<Long>();
g2mMap.put(groupL, modelSet);
}
assert n2nMap.getLong(node2) != BackupRestoreSession.NONE;
@@ -459,10 +459,10 @@
// entire TRIPLES section with one call to modifyModel().
if (node3 == -1) {
// This is a group node that maps to multiple model nodes.
- Set modelSet = (Set)g2mMap.get(new Long(meta));
+ Set<Long> modelSet = g2mMap.get(new Long(meta));
assert modelSet != null;
- for (Iterator it = modelSet.iterator(); it.hasNext(); ) {
- node3 = ((Long)it.next()).longValue();
+ for (Iterator<Long> it = modelSet.iterator(); it.hasNext(); ) {
+ node3 = it.next().longValue();
resolver.modifyModel(
node3,
new SingletonStatements(node0, node1, node2),
@@ -526,6 +526,7 @@
String line;
do {
line = br.readLine();
+ if (line == null) throw new QueryException("Unexpected EOF in header section while restoring from backup file: " + sourceURI);
} while (!line.equals("RDFNODES"));
// Remove all statements from store except those reserving
Modified: trunk/src/jar/resolver-memory/java/org/mulgara/resolver/memory/Stating.java
===================================================================
--- trunk/src/jar/resolver-memory/java/org/mulgara/resolver/memory/Stating.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/resolver-memory/java/org/mulgara/resolver/memory/Stating.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -66,10 +66,9 @@
public boolean equals(Object object)
{
- if (getClass() == object.getClass()) {
+ if (object != null && getClass() == object.getClass()) {
return Arrays.equals(x, ((Stating) object).x);
- }
- else {
+ } else {
return false;
}
}
Modified: trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java
===================================================================
--- trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/server/java/org/mulgara/server/EmbeddedMulgaraServer.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -234,7 +234,7 @@
} finally {
// attempt to close the socket
try {
- clientSocket.close();
+ if (clientSocket != null) clientSocket.close();
} catch (Exception ex) {
/* skip */
}
Modified: trunk/src/jar/tuples/java/org/mulgara/store/tuples/UnboundJoin.java
===================================================================
--- trunk/src/jar/tuples/java/org/mulgara/store/tuples/UnboundJoin.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/tuples/java/org/mulgara/store/tuples/UnboundJoin.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -401,7 +401,7 @@
if (rowCount == null) rowCount = BigInteger.valueOf(groupResult);
else rowCount = rowCount.multiply(BigInteger.valueOf(groupResult));
}
- return rowCount.longValue();
+ return (rowCount == null) ? 0L : rowCount.longValue();
}
}
Modified: trunk/src/jar/util/java/org/mulgara/util/ObjectUtil.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/ObjectUtil.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/util/java/org/mulgara/util/ObjectUtil.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -38,4 +38,16 @@
public static final boolean eq(Object a, Object b) {
return a == null ? b == null : a.equals(b);
}
+
+ /**
+ * Obtain a class loader for an object.
+ * @param o The object to get the classloader for.
+ * @return The classloader that loaded the class of o.
+ */
+ public static ClassLoader getClassLoader(Object o) {
+ ClassLoader c = o.getClass().getClassLoader();
+ if (c == null) c = ClassLoader.getSystemClassLoader();
+ if (c == null) throw new RuntimeException("Can't find a class loader");
+ return c;
+ }
}
Modified: trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java
===================================================================
--- trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -57,6 +57,7 @@
import org.mulgara.query.operation.Load;
import org.mulgara.server.SessionFactoryProvider;
import org.mulgara.sparql.SparqlInterpreter;
+import org.mulgara.util.ObjectUtil;
import org.mulgara.util.SparqlUtil;
import org.mulgara.util.StackTrace;
import org.mulgara.util.functional.C;
@@ -171,7 +172,7 @@
*/
private void init(String hostname, String servername) {
if (!initialized) {
- URL path = getClass().getClassLoader().getResource(ResourceFile.RESOURCES + getTemplateFile());
+ URL path = ObjectUtil.getClassLoader(this).getResource(ResourceFile.RESOURCES + getTemplateFile());
if (path == null) throw new MissingResourceException("Missing template file", getClass().getName(), ResourceFile.RESOURCES + getTemplateFile());
templatePath = path.toString();
resourcePath = templatePath.split("!")[0];
@@ -285,7 +286,7 @@
// work out which commands to run
String command = generateCommand(req, graphUri);
- if (DEBUG && command.contains(DEBUG_HOOK)) {
+ if (DEBUG && command != null && command.contains(DEBUG_HOOK)) {
outputFile(resp, DEBUG_PAGE);
return;
}
Modified: trunk/src/jar/web/java/org/mulgara/webquery/ResourceFile.java
===================================================================
--- trunk/src/jar/web/java/org/mulgara/webquery/ResourceFile.java 2011-09-15 01:55:45 UTC (rev 2027)
+++ trunk/src/jar/web/java/org/mulgara/webquery/ResourceFile.java 2011-09-15 01:56:09 UTC (rev 2028)
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.InputStream;
+import static org.mulgara.util.ObjectUtil.getClassLoader;
public abstract class ResourceFile {
@@ -40,7 +41,7 @@
* @return An InputStream for accessing the resource file.
*/
protected InputStream getStream() throws IOException {
- InputStream in = getClass().getClassLoader().getResourceAsStream(resourceFile);
+ InputStream in = getClassLoader(this).getResourceAsStream(resourceFile);
if (in == null) throw new IOException("Unable to load resource: " + resourceFile);
return in;
}
More information about the Mulgara-svn
mailing list