fix potential bugs

This commit is contained in:
Sebastian Sdorra
2012-07-24 20:12:46 +02:00
parent 23b3702570
commit 85231e7f03
21 changed files with 123 additions and 42 deletions

View File

@@ -43,6 +43,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
import java.util.Properties;
/**
@@ -205,7 +206,7 @@ public class BasicContextProvider implements SCMContextProvider
if (!directory.exists() &&!directory.mkdirs())
{
String msg = "could not create home directory at ".concat(
directory.getAbsolutePath());
directory.getAbsolutePath());
// do not use logger
// http://www.slf4j.org/codes.html#substituteLogger
@@ -234,7 +235,7 @@ public class BasicContextProvider implements SCMContextProvider
{
try
{
s = Stage.valueOf(stageProperty.toUpperCase());
s = Stage.valueOf(stageProperty.toUpperCase(Locale.ENGLISH));
}
catch (IllegalArgumentException ex)
{
@@ -318,8 +319,8 @@ public class BasicContextProvider implements SCMContextProvider
catch (IOException ex)
{
throw new ConfigurationException(
"could not load properties form resource ".concat(
DIRECTORY_RESOURCE), ex);
"could not load properties form resource ".concat(DIRECTORY_RESOURCE),
ex);
}
finally
{

View File

@@ -37,6 +37,10 @@ package sonia.scm;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.util.Locale;
/**
* Represents the platform on which the SCM manager running.
*
@@ -66,9 +70,9 @@ public class Platform
arch = osArch;
}
arch = arch.toLowerCase();
arch = arch.toLowerCase(Locale.ENGLISH);
x64 = "64".equals(arch) || "x86_64".equals(arch) || "ppc64".equals(arch)
|| "sparcv9".equals(arch) || "amd64".equals(arch);
|| "sparcv9".equals(arch) || "amd64".equals(arch);
type = PlatformType.createPlatformType(osName);
}

View File

@@ -33,6 +33,8 @@
package sonia.scm;
import java.util.Locale;
/**
* Type of the SCM-Manager host platform.
*
@@ -69,7 +71,7 @@ public enum PlatformType
*/
public static PlatformType createPlatformType(String osName)
{
osName = osName.toLowerCase();
osName = osName.toLowerCase(Locale.ENGLISH);
PlatformType type = PlatformType.UNSPECIFIED;

View File

@@ -33,11 +33,16 @@
package sonia.scm.io;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.Closeables;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
@@ -71,7 +76,17 @@ public abstract class AbstractWriter<T>
*/
public void write(T object, File file) throws IOException
{
write(object, new FileOutputStream(file));
OutputStream output = null;
try
{
output = new FileOutputStream(file);
write(object, output);
}
finally
{
Closeables.closeQuietly(output);
}
}
/**

View File

@@ -46,6 +46,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@@ -250,7 +251,7 @@ public class PluginCondition implements Cloneable, Serializable
*/
private boolean isOs(String osType, PlatformType type)
{
osType = osType.toLowerCase();
osType = osType.toLowerCase(Locale.ENGLISH);
return ((osType.indexOf("win") >= 0) && (PlatformType.WINDOWS == type))
|| ((osType.indexOf("unix") >= 0) && type.isUnix())

View File

@@ -39,6 +39,8 @@ import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.io.Serializable;
import java.util.Comparator;
/**
@@ -47,13 +49,16 @@ import java.util.Comparator;
* @since 1.6
*/
public class PluginInformationComparator
implements Comparator<PluginInformation>
implements Comparator<PluginInformation>, Serializable
{
/** Field description */
public static final PluginInformationComparator INSTANCE =
new PluginInformationComparator();
/** Field description */
private static final long serialVersionUID = -8339752498853225668L;
//~--- methods --------------------------------------------------------------
/**

View File

@@ -35,6 +35,7 @@ package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -462,7 +463,7 @@ public class PluginVersion implements Comparable<PluginVersion>
*/
private void parseQualifierPart(String qualifierPart)
{
String qualifier = qualifierPart.trim().toLowerCase();
String qualifier = qualifierPart.trim().toLowerCase(Locale.ENGLISH);
if (qualifier.contains("snapshot"))
{

View File

@@ -30,6 +30,7 @@
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
@@ -39,6 +40,7 @@ import com.google.common.base.Objects;
//~--- JDK imports ------------------------------------------------------------
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@@ -49,11 +51,16 @@ import javax.xml.bind.annotation.XmlRootElement;
* @author Sebastian Sdorra
* @since 1.18
*/
@XmlRootElement(name="branch")
@XmlRootElement(name = "branch")
@XmlAccessorType(XmlAccessType.FIELD)
public final class Branch implements Serializable
{
/** Field description */
private static final long serialVersionUID = -4602244691711222413L;
//~--- constructors ---------------------------------------------------------
/**
* Constructs a new instance of branch.
* This constructor should only be called from JAXB.

View File

@@ -39,19 +39,25 @@ import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.io.Serializable;
import java.util.Comparator;
/**
*
* @author Sebastian Sdorra
*/
public class FileObjectNameComparator implements Comparator<FileObject>
public class FileObjectNameComparator
implements Comparator<FileObject>, Serializable
{
/** Field description */
public static final FileObjectNameComparator instance =
new FileObjectNameComparator();
/** Field description */
private static final long serialVersionUID = -2133224334287527874L;
//~--- methods --------------------------------------------------------------
/**

View File

@@ -41,6 +41,11 @@ package sonia.scm.repository.spi;
public final class BlameCommandRequest extends FileBaseCommandRequest
{
/** Field description */
private static final long serialVersionUID = 6421975024231127315L;
//~--- methods --------------------------------------------------------------
/**
* Method description
*

View File

@@ -33,14 +33,14 @@
package sonia.scm.repository.spi;
//~--- JDK imports ------------------------------------------------------------
import java.io.Serializable;
/**
*
* @author Sebastian Sdorra
* @since 1.17
*/
public final class BrowseCommandRequest extends FileBaseCommandRequest
implements Resetable, Serializable {}
{
/** Field description */
private static final long serialVersionUID = 7956624623516803183L;
}

View File

@@ -39,9 +39,13 @@ package sonia.scm.repository.spi;
* @since 1.17
*/
public final class CatCommandRequest extends FileBaseCommandRequest
implements Cloneable
{
/** Field description */
private static final long serialVersionUID = -6404958421249874551L;
//~--- methods --------------------------------------------------------------
/**
* Method description
*

View File

@@ -45,9 +45,14 @@ import sonia.scm.Validateable;
* @since 1.17
*/
public final class DiffCommandRequest extends FileBaseCommandRequest
implements Cloneable, Validateable
implements Validateable
{
/** Field description */
private static final long serialVersionUID = 4026911212676859626L;
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -85,6 +90,6 @@ public final class DiffCommandRequest extends FileBaseCommandRequest
public boolean isValid()
{
return !Strings.isNullOrEmpty(getPath())
||!Strings.isNullOrEmpty(getRevision());
||!Strings.isNullOrEmpty(getRevision());
}
}

View File

@@ -47,9 +47,14 @@ import java.io.Serializable;
* @since 1.17
*/
public abstract class FileBaseCommandRequest
implements Resetable, Serializable, Cloneable
implements Resetable, Serializable, Cloneable
{
/** Field description */
private static final long serialVersionUID = -3442101119408346165L;
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -74,7 +79,7 @@ public abstract class FileBaseCommandRequest
final FileBaseCommandRequest other = (FileBaseCommandRequest) obj;
return Objects.equal(path, other.path)
&& Objects.equal(revision, other.revision);
&& Objects.equal(revision, other.revision);
}
/**
@@ -189,7 +194,7 @@ public abstract class FileBaseCommandRequest
// this shouldn't happen, since we are Cloneable
throw new InternalError(
"FileBaseCommandRequest seems not to be cloneable");
"FileBaseCommandRequest seems not to be cloneable");
}
return clone;

View File

@@ -49,6 +49,11 @@ import java.io.Serializable;
public final class LogCommandRequest implements Serializable, Resetable
{
/** Field description */
private static final long serialVersionUID = 8759598040394428649L;
//~--- methods --------------------------------------------------------------
/**
* Method description
*
@@ -73,10 +78,10 @@ public final class LogCommandRequest implements Serializable, Resetable
final LogCommandRequest other = (LogCommandRequest) obj;
return Objects.equal(startChangeset, other.startChangeset)
&& Objects.equal(endChangeset, other.endChangeset)
&& Objects.equal(pagingStart, other.pagingStart)
&& Objects.equal(pagingLimit, other.pagingLimit)
&& Objects.equal(path, other.path);
&& Objects.equal(endChangeset, other.endChangeset)
&& Objects.equal(pagingStart, other.pagingStart)
&& Objects.equal(pagingLimit, other.pagingLimit)
&& Objects.equal(path, other.path);
}
/**
@@ -89,7 +94,7 @@ public final class LogCommandRequest implements Serializable, Resetable
public int hashCode()
{
return Objects.hashCode(startChangeset, endChangeset, pagingStart,
pagingLimit, path);
pagingLimit, path);
}
/**

View File

@@ -30,6 +30,7 @@
*/
package sonia.scm.resources;
//~--- non-JDK imports --------------------------------------------------------
@@ -38,6 +39,8 @@ import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.io.Serializable;
import java.util.Comparator;
/**
@@ -46,13 +49,17 @@ import java.util.Comparator;
* @author Sebastian Sdorra
* @since 1.16
*/
public class ResourceNameComparator implements Comparator<Resource>
public class ResourceNameComparator
implements Comparator<Resource>, Serializable
{
/** Field description */
public static final ResourceNameComparator INSTANCE =
new ResourceNameComparator();
/** Field description */
private static final long serialVersionUID = 3474356901608301437L;
//~--- methods --------------------------------------------------------------
/**

View File

@@ -44,6 +44,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
/**
*
@@ -185,7 +186,7 @@ public class SearchUtil
if (request.isIgnoreCase())
{
query = query.toLowerCase();
query = query.toLowerCase(Locale.ENGLISH);
}
query = query.replace("*", ".*").replace("?", ".");

View File

@@ -59,6 +59,7 @@ import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
/**
*
@@ -411,7 +412,7 @@ public class IOUtil
public static void extract(File archive, File outputDirectory)
throws IOException
{
String name = archive.getName().toLowerCase();
String name = archive.getName().toLowerCase(Locale.ENGLISH);
extract(archive, outputDirectory, name);
}

View File

@@ -44,6 +44,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -89,7 +90,7 @@ public abstract class AbstractCGIServlet extends HttpServlet
* @throws ServletException
*/
protected abstract File getCommand(HttpServletRequest req)
throws ServletException, IOException;
throws ServletException, IOException;
//~--- methods --------------------------------------------------------------
@@ -133,7 +134,8 @@ public abstract class AbstractCGIServlet extends HttpServlet
{
String os = System.getProperty("os.name");
if ((os != null) && (os.toLowerCase().indexOf("windows") != -1))
if ((os != null)
&& (os.toLowerCase(Locale.ENGLISH).indexOf("windows") != -1))
{
env.set("SystemRoot", "C:\\WINDOWS");
}
@@ -155,8 +157,8 @@ public abstract class AbstractCGIServlet extends HttpServlet
* @throws ServletException
*/
protected EnvList createRequestEnvironment(HttpServletRequest request,
EnvList baseEnvironment)
throws ServletException
EnvList baseEnvironment)
throws ServletException
{
return new EnvList(baseEnvironment);
}
@@ -173,11 +175,11 @@ public abstract class AbstractCGIServlet extends HttpServlet
*/
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
throws ServletException, IOException
{
cgiRunner.exec(createRequestEnvironment(req, baseEnvironment),
getCmdPrefix(), getCommand(req), req.getPathInfo(), req,
resp, HttpUtil.getServerPort(configuration, req));
getCmdPrefix(), getCommand(req), req.getPathInfo(), req, resp,
HttpUtil.getServerPort(configuration, req));
}
//~--- get methods ----------------------------------------------------------

View File

@@ -49,6 +49,7 @@ import sonia.scm.util.Util;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map.Entry;
import javax.servlet.FilterChain;
@@ -296,6 +297,6 @@ public class LoggingFilter extends HttpFilter
private boolean isTextRequest(String contentType)
{
return !Strings.isNullOrEmpty(contentType)
&& contentType.toLowerCase().startsWith("text");
&& contentType.toLowerCase(Locale.ENGLISH).startsWith("text");
}
}

View File

@@ -74,6 +74,9 @@ public class ProxyServet extends HttpServlet
private static final Logger logger =
LoggerFactory.getLogger(ProxyServet.class);
/** Field description */
private static final long serialVersionUID = -8069773175342430809L;
//~--- constructors ---------------------------------------------------------
/**
@@ -144,14 +147,14 @@ public class ProxyServet extends HttpServlet
response.setStatus(con.getResponseCode());
for (Iterator i = con.getHeaderFields().entrySet().iterator();
i.hasNext(); )
i.hasNext(); )
{
Map.Entry mapEntry = (Map.Entry) i.next();
if (mapEntry.getKey() != null)
{
response.setHeader(mapEntry.getKey().toString(),
((List) mapEntry.getValue()).get(0).toString());
((List) mapEntry.getValue()).get(0).toString());
}
}