Skip to content

Commit

Permalink
style: update checkstyle + turn on some rules (#847)
Browse files Browse the repository at this point in the history
1. Update checkstyle to 7.8.2
2. Add checkstyle module "RedundantModifier"
3. Uncomment checkstyle modules "ArrayTypeStyle", "ModifierOrder"
  • Loading branch information
AlexElin authored and vlsi committed Jul 23, 2017
1 parent 0221f93 commit 246b759
Show file tree
Hide file tree
Showing 67 changed files with 332 additions and 327 deletions.
2 changes: 1 addition & 1 deletion pgjdbc/pom.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<jdbc.specification.version>4.2</jdbc.specification.version> <jdbc.specification.version>4.2</jdbc.specification.version>
<jdbc.specification.version.nodot>42</jdbc.specification.version.nodot> <jdbc.specification.version.nodot>42</jdbc.specification.version.nodot>
<skip.assembly>false</skip.assembly> <skip.assembly>false</skip.assembly>
<checkstyle.version>7.4</checkstyle.version> <checkstyle.version>7.8.2</checkstyle.version>
</properties> </properties>


<profiles> <profiles>
Expand Down
5 changes: 3 additions & 2 deletions pgjdbc/src/main/checkstyle/checks.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@
</module> </module>
<module name="OneStatementPerLine"/> <module name="OneStatementPerLine"/>
<module name="MultipleVariableDeclarations"/> <module name="MultipleVariableDeclarations"/>
<!--<module name="ArrayTypeStyle"/>--> <module name="ArrayTypeStyle"/>
<!--<module name="MissingSwitchDefault"/>--> <!--<module name="MissingSwitchDefault"/>-->
<!--<module name="FallThrough"/>--> <!--<module name="FallThrough"/>-->
<module name="UpperEll"/> <module name="UpperEll"/>
<!--<module name="ModifierOrder"/>--> <module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<module name="EmptyLineSeparator"> <module name="EmptyLineSeparator">
<property name="allowNoEmptyLineBetweenFields" value="true"/> <property name="allowNoEmptyLineBetweenFields" value="true"/>
</module> </module>
Expand Down
6 changes: 3 additions & 3 deletions pgjdbc/src/main/java/org/postgresql/PGProperty.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ public enum PGProperty {
private String _description; private String _description;
private String[] _choices; private String[] _choices;


private PGProperty(String name, String defaultValue, String description) { PGProperty(String name, String defaultValue, String description) {
this(name, defaultValue, description, false); this(name, defaultValue, description, false);
} }


private PGProperty(String name, String defaultValue, String description, boolean required) { PGProperty(String name, String defaultValue, String description, boolean required) {
this(name, defaultValue, description, required, (String[]) null); this(name, defaultValue, description, required, (String[]) null);
} }


private PGProperty(String name, String defaultValue, String description, boolean required, PGProperty(String name, String defaultValue, String description, boolean required,
String... choices) { String... choices) {
_name = name; _name = name;
_defaultValue = defaultValue; _defaultValue = defaultValue;
Expand Down
2 changes: 1 addition & 1 deletion pgjdbc/src/main/java/org/postgresql/copy/CopyManager.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CopyManager {
// do figure it out we can just set it here and they reap the rewards. // do figure it out we can just set it here and they reap the rewards.
// Note that this is currently being used for both a number of bytes and a number // Note that this is currently being used for both a number of bytes and a number
// of characters. // of characters.
final static int DEFAULT_BUFFER_SIZE = 65536; static final int DEFAULT_BUFFER_SIZE = 65536;


private final Encoding encoding; private final Encoding encoding;
private final QueryExecutor queryExecutor; private final QueryExecutor queryExecutor;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* Creates an instance of {@link CachedQuery} for a given connection. * Creates an instance of {@link CachedQuery} for a given connection.
*/ */
class CachedQueryCreateAction implements LruCache.CreateAction<Object, CachedQuery> { class CachedQueryCreateAction implements LruCache.CreateAction<Object, CachedQuery> {
private final static String[] EMPTY_RETURNING = new String[0]; private static final String[] EMPTY_RETURNING = new String[0];
private final QueryExecutor queryExecutor; private final QueryExecutor queryExecutor;


public CachedQueryCreateAction(QueryExecutor queryExecutor) { CachedQueryCreateAction(QueryExecutor queryExecutor) {
this.queryExecutor = queryExecutor; this.queryExecutor = queryExecutor;
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* syntax, thus a special cache key class is used to trigger proper parsing for callable statements. * syntax, thus a special cache key class is used to trigger proper parsing for callable statements.
*/ */
class CallableQueryKey extends BaseQueryKey { class CallableQueryKey extends BaseQueryKey {
public CallableQueryKey(String sql) {
CallableQueryKey(String sql) {
super(sql, true, true); super(sql, true, true);
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static class Translation {
} }
} }


private final static Translation[] FATAL_TRANSLATIONS = private static final Translation[] FATAL_TRANSLATIONS =
new Translation[]{ new Translation[]{
new Translation("ВАЖНО", null, "ru", "WIN", "ALT", "KOI8"), new Translation("ВАЖНО", null, "ru", "WIN", "ALT", "KOI8"),
new Translation("致命错误", null, "zh_CN", "EUC_CN", "GBK", "BIG5"), new Translation("致命错误", null, "zh_CN", "EUC_CN", "GBK", "BIG5"),
Expand Down
6 changes: 3 additions & 3 deletions pgjdbc/src/main/java/org/postgresql/core/NativeQuery.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* replaced with $1, $2, etc. * replaced with $1, $2, etc.
*/ */
public class NativeQuery { public class NativeQuery {
private final static String[] BIND_NAMES = new String[128 * 10]; private static final String[] BIND_NAMES = new String[128 * 10];
private final static int[] NO_BINDS = new int[0]; private static final int[] NO_BINDS = new int[0];


public final String nativeSql; public final String nativeSql;
public final int[] bindPositions; public final int[] bindPositions;
Expand Down Expand Up @@ -42,7 +42,7 @@ public NativeQuery(String nativeSql, int[] bindPositions, boolean multiStatement
* parameter placeholders. * parameter placeholders.
* *
* @param parameters a ParameterList returned by this Query's {@link Query#createParameterList} * @param parameters a ParameterList returned by this Query's {@link Query#createParameterList}
* method, or <code>null</code> to leave the parameter placeholders unsubstituted. * method, or {@code null} to leave the parameter placeholders unsubstituted.
* @return a human-readable representation of this query * @return a human-readable representation of this query
*/ */
public String toString(ParameterList parameters) { public String toString(ParameterList parameters) {
Expand Down
6 changes: 3 additions & 3 deletions pgjdbc/src/main/java/org/postgresql/core/PGStream.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void sendInteger2(int val) throws IOException {
* @param buf The array of bytes to be sent * @param buf The array of bytes to be sent
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
public void send(byte buf[]) throws IOException { public void send(byte[] buf) throws IOException {
pg_output.write(buf); pg_output.write(buf);
} }


Expand All @@ -242,7 +242,7 @@ public void send(byte buf[]) throws IOException {
* @param siz the number of bytes to be sent * @param siz the number of bytes to be sent
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
public void send(byte buf[], int siz) throws IOException { public void send(byte[] buf, int siz) throws IOException {
send(buf, 0, siz); send(buf, 0, siz);
} }


Expand All @@ -255,7 +255,7 @@ public void send(byte buf[], int siz) throws IOException {
* @param siz the number of bytes to be sent * @param siz the number of bytes to be sent
* @throws IOException if an I/O error occurs * @throws IOException if an I/O error occurs
*/ */
public void send(byte buf[], int off, int siz) throws IOException { public void send(byte[] buf, int off, int siz) throws IOException {
int bufamt = buf.length - off; int bufamt = buf.length - off;
pg_output.write(buf, off, bufamt < siz ? bufamt : siz); pg_output.write(buf, off, bufamt < siz ? bufamt : siz);
for (int i = bufamt; i < siz; ++i) { for (int i = bufamt; i < siz; ++i) {
Expand Down
6 changes: 3 additions & 3 deletions pgjdbc/src/main/java/org/postgresql/core/Parser.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Christopher Deckers (chrriis@gmail.com) * @author Christopher Deckers (chrriis@gmail.com)
*/ */
public class Parser { public class Parser {
private final static int[] NO_BINDS = new int[0]; private static final int[] NO_BINDS = new int[0];


/** /**
* Parses JDBC query into PostgreSQL's native format. Several queries might be given if separated * Parses JDBC query into PostgreSQL's native format. Several queries might be given if separated
Expand Down Expand Up @@ -1197,8 +1197,8 @@ private static String escapeFunction(String functionName, String args, boolean s
} }
} }


private final static char[] QUOTE_OR_ALPHABETIC_MARKER = new char[]{'\"', '0'}; private static final char[] QUOTE_OR_ALPHABETIC_MARKER = {'\"', '0'};
private final static char[] SINGLE_QUOTE = new char[]{'\''}; private static final char[] SINGLE_QUOTE = {'\''};


// Static variables for parsing SQL when replaceProcessing is true. // Static variables for parsing SQL when replaceProcessing is true.
private enum SqlParseState { private enum SqlParseState {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class QueryWithReturningColumnsKey extends BaseQueryKey { class QueryWithReturningColumnsKey extends BaseQueryKey {
public final String[] columnNames; public final String[] columnNames;


public QueryWithReturningColumnsKey(String sql, boolean isParameterized, boolean escapeProcessing, QueryWithReturningColumnsKey(String sql, boolean isParameterized, boolean escapeProcessing,
String[] columnNames) { String[] columnNames) {
super(sql, isParameterized, escapeProcessing); super(sql, isParameterized, escapeProcessing);
if (columnNames == null) { if (columnNames == null) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum ServerVersion implements Version {


private final int version; private final int version;


private ServerVersion(String version) { ServerVersion(String version) {
this.version = parseServerVersionStr(version); this.version = parseServerVersionStr(version);
} }


Expand Down
2 changes: 1 addition & 1 deletion pgjdbc/src/main/java/org/postgresql/core/Utils.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static String toHexString(byte[] data) {
* Keep a local copy of the UTF-8 Charset so we can avoid synchronization overhead from looking up * Keep a local copy of the UTF-8 Charset so we can avoid synchronization overhead from looking up
* the Charset by name as String.getBytes(String) requires. * the Charset by name as String.getBytes(String) requires.
*/ */
private final static Charset utf8Charset = Charset.forName("UTF-8"); private static final Charset utf8Charset = Charset.forName("UTF-8");


/** /**
* Encode a string as UTF-8. * Encode a string as UTF-8.
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void moveBufferTo(byte[] dest) {
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public int read(byte to[], int off, int len) throws IOException { public int read(byte[] to, int off, int len) throws IOException {
if ((off | len | (off + len) | (to.length - (off + len))) < 0) { if ((off | len | (off + len) | (to.length - (off + len))) < 0) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} else if (len == 0) { } else if (len == 0) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public int getOutParameterCount() {
} }


public int[] getTypeOIDs() { public int[] getTypeOIDs() {
int oids[] = new int[total]; int[] oids = new int[total];
for (int i = 0; i < offsets.length; i++) { for (int i = 0; i < offsets.length; i++) {
int subOids[] = subparams[i].getTypeOIDs(); int[] subOids = subparams[i].getTypeOIDs();
System.arraycopy(subOids, 0, oids, offsets[i], subOids.length); System.arraycopy(subOids, 0, oids, offsets[i], subOids.length);
} }
return oids; return oids;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DescribeRequest {
public final boolean describeOnly; public final boolean describeOnly;
public final String statementName; public final String statementName;


public DescribeRequest(SimpleQuery query, SimpleParameterList parameterList, DescribeRequest(SimpleQuery query, SimpleParameterList parameterList,
boolean describeOnly, String statementName) { boolean describeOnly, String statementName) {
this.query = query; this.query = query;
this.parameterList = parameterList; this.parameterList = parameterList;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExecuteRequest {
public final Portal portal; public final Portal portal;
public final boolean asSimple; public final boolean asSimple;


public ExecuteRequest(SimpleQuery query, Portal portal, boolean asSimple) { ExecuteRequest(SimpleQuery query, Portal portal, boolean asSimple) {
this.query = query; this.query = query;
this.portal = portal; this.portal = portal;
this.asSimple = asSimple; this.asSimple = asSimple;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ private byte[] receiveFastpathResult() throws IOException, SQLException {
LOGGER.log(Level.FINEST, " <=BE FunctionCallResponse({0} bytes)", valueLen); LOGGER.log(Level.FINEST, " <=BE FunctionCallResponse({0} bytes)", valueLen);


if (valueLen != -1) { if (valueLen != -1) {
byte buf[] = new byte[valueLen]; byte[] buf = new byte[valueLen];
pgStream.receive(buf, 0, valueLen); pgStream.receive(buf, 0, valueLen);
returnValue = buf; returnValue = buf;
} }
Expand Down Expand Up @@ -819,7 +819,7 @@ public synchronized CopyOperation startCopy(String sql, boolean suppressBegin)
if (!suppressBegin) { if (!suppressBegin) {
doSubprotocolBegin(); doSubprotocolBegin();
} }
byte buf[] = Utils.encodeUTF8(sql); byte[] buf = Utils.encodeUTF8(sql);


try { try {
LOGGER.log(Level.FINEST, " FE=> Query(CopyStart)"); LOGGER.log(Level.FINEST, " FE=> Query(CopyStart)");
Expand Down Expand Up @@ -1786,8 +1786,8 @@ private void sendOneQuery(SimpleQuery query, SimpleParameterList params, int max
|| (!oneShot && paramsHasUnknown && queryHasUnknown && !query.isStatementDescribed()); || (!oneShot && paramsHasUnknown && queryHasUnknown && !query.isStatementDescribed());


if (!describeStatement && paramsHasUnknown && !queryHasUnknown) { if (!describeStatement && paramsHasUnknown && !queryHasUnknown) {
int queryOIDs[] = query.getStatementTypes(); int[] queryOIDs = query.getStatementTypes();
int paramOIDs[] = params.getTypeOIDs(); int[] paramOIDs = params.getTypeOIDs();
for (int i = 0; i < paramOIDs.length; i++) { for (int i = 0; i < paramOIDs.length; i++) {
// Only supply type information when there isn't any // Only supply type information when there isn't any
// already, don't arbitrarily overwrite user supplied // already, don't arbitrarily overwrite user supplied
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
*/ */
class SimpleParameterList implements V3ParameterList { class SimpleParameterList implements V3ParameterList {


private final static byte IN = 1; private static final byte IN = 1;
private final static byte OUT = 2; private static final byte OUT = 2;
private final static byte INOUT = IN | OUT; private static final byte INOUT = IN | OUT;


private final static byte TEXT = 0; private static final byte TEXT = 0;
private final static byte BINARY = 4; private static final byte BINARY = 4;


SimpleParameterList(int paramCount, TypeTransferModeRegistry transferModeRegistry) { SimpleParameterList(int paramCount, TypeTransferModeRegistry transferModeRegistry) {
this.paramValues = new Object[paramCount]; this.paramValues = new Object[paramCount];
Expand Down Expand Up @@ -467,7 +467,7 @@ public String toString() {
* Marker object representing NULL; this distinguishes "parameter never set" from "parameter set * Marker object representing NULL; this distinguishes "parameter never set" from "parameter set
* to null". * to null".
*/ */
private final static Object NULL_OBJECT = new Object(); private static final Object NULL_OBJECT = new Object();


private int pos = 0; private int pos = 0;
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -316,5 +316,5 @@ public SqlCommand getSqlCommand() {


private Integer cachedMaxResultRowSize; private Integer cachedMaxResultRowSize;


final static SimpleParameterList NO_PARAMETERS = new SimpleParameterList(0, null); static final SimpleParameterList NO_PARAMETERS = new SimpleParameterList(0, null);
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -248,10 +248,11 @@ private class ConnectionHandler implements InvocationHandler {
private Connection proxy; // the Connection the client is currently using, which is a proxy private Connection proxy; // the Connection the client is currently using, which is a proxy
private boolean automatic = false; private boolean automatic = false;


public ConnectionHandler(Connection con) { ConnectionHandler(Connection con) {
this.con = con; this.con = con;
} }


@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
final String methodName = method.getName(); final String methodName = method.getName();
// From Object // From Object
Expand Down Expand Up @@ -375,11 +376,12 @@ private class StatementHandler implements InvocationHandler {
private ConnectionHandler con; private ConnectionHandler con;
private Statement st; private Statement st;


public StatementHandler(ConnectionHandler con, Statement st) { StatementHandler(ConnectionHandler con, Statement st) {
this.con = con; this.con = con;
this.st = st; this.st = st;
} }


@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
final String methodName = method.getName(); final String methodName = method.getName();
// From Object // From Object
Expand Down
2 changes: 1 addition & 1 deletion pgjdbc/src/main/java/org/postgresql/fastpath/Fastpath.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Fastpath {
// Java passes oids around as longs, but in the backend // Java passes oids around as longs, but in the backend
// it's an unsigned int, so we use this to make the conversion // it's an unsigned int, so we use this to make the conversion
// of long -> signed int which the backend interprets as unsigned. // of long -> signed int which the backend interprets as unsigned.
private final static long NUM_OIDS = 4294967296L; // 2^32 private static final long NUM_OIDS = 4294967296L; // 2^32


// This maps the functions names to their id's (possible unique just // This maps the functions names to their id's (possible unique just
// to a connection). // to a connection).
Expand Down
4 changes: 2 additions & 2 deletions pgjdbc/src/main/java/org/postgresql/fastpath/FastpathArg.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public FastpathArg(long value) {
* *
* @param bytes array to store * @param bytes array to store
*/ */
public FastpathArg(byte bytes[]) { public FastpathArg(byte[] bytes) {
this(bytes, 0, bytes.length); this(bytes, 0, bytes.length);
} }


Expand All @@ -76,7 +76,7 @@ public FastpathArg(byte bytes[]) {
* @param off offset within array * @param off offset within array
* @param len length of data to include * @param len length of data to include
*/ */
public FastpathArg(byte buf[], int off, int len) { public FastpathArg(byte[] buf, int off, int len) {
this.bytes = buf; this.bytes = buf;
this.bytesStart = off; this.bytesStart = off;
this.bytesLength = len; this.bytesLength = len;
Expand Down
2 changes: 1 addition & 1 deletion pgjdbc/src/main/java/org/postgresql/geometric/PGbox.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PGbox extends PGobject implements PGBinaryObject, Serializable, Clo
/** /**
* These are the two points. * These are the two points.
*/ */
public PGpoint point[] = new PGpoint[2]; public PGpoint[] point = new PGpoint[2];


/** /**
* @param x1 first x coordinate * @param x1 first x coordinate
Expand Down
2 changes: 1 addition & 1 deletion pgjdbc/src/main/java/org/postgresql/geometric/PGlseg.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class PGlseg extends PGobject implements Serializable, Cloneable {
/** /**
* These are the two points. * These are the two points.
*/ */
public PGpoint point[] = new PGpoint[2]; public PGpoint[] point = new PGpoint[2];


/** /**
* @param x1 coordinate for first point * @param x1 coordinate for first point
Expand Down
2 changes: 1 addition & 1 deletion pgjdbc/src/main/java/org/postgresql/geometric/PGpath.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PGpath extends PGobject implements Serializable, Cloneable {
/** /**
* The points defining this path * The points defining this path
*/ */
public PGpoint points[]; public PGpoint[] points;


/** /**
* @param points the PGpoints that define the path * @param points the PGpoints that define the path
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PGpolygon extends PGobject implements Serializable, Cloneable {
/** /**
* The points defining the polygon * The points defining the polygon
*/ */
public PGpoint points[]; public PGpoint[] points;


/** /**
* Creates a polygon using an array of PGpoints * Creates a polygon using an array of PGpoints
Expand Down
Loading

0 comments on commit 246b759

Please sign in to comment.