From ec17eea1e016e9064cc7aa88ff5c1078cce90bde Mon Sep 17 00:00:00 2001 From: redkale Date: Thu, 24 Oct 2024 16:00:12 +0800 Subject: [PATCH] sonar --- .../java/org/redkale/boot/NodeServer.java | 7 +- .../org/redkale/cluster/spi/ClusterAgent.java | 5 +- .../org/redkale/convert/ConvertFactory.java | 7 +- .../convert/pb/ProtobufDynEncoder.java | 3 - .../java/org/redkale/net/AsyncConnection.java | 2 + src/main/java/org/redkale/net/Server.java | 22 ++- .../org/redkale/source/DataJdbcSource.java | 4 +- src/main/java/org/redkale/util/Utility.java | 131 +++++++++--------- 8 files changed, 81 insertions(+), 100 deletions(-) diff --git a/src/main/java/org/redkale/boot/NodeServer.java b/src/main/java/org/redkale/boot/NodeServer.java index d1c0d7ba0..a8099ae6d 100644 --- a/src/main/java/org/redkale/boot/NodeServer.java +++ b/src/main/java/org/redkale/boot/NodeServer.java @@ -470,11 +470,8 @@ public abstract class NodeServer { } protected boolean acceptsComponent(Class serviceImplClass) { - if (Modifier.isAbstract(serviceImplClass.getModifiers()) - || Modifier.isInterface(serviceImplClass.getModifiers())) { - return false; - } - return true; + return !(Modifier.isAbstract(serviceImplClass.getModifiers()) + || Modifier.isInterface(serviceImplClass.getModifiers())); } protected boolean interceptComponent(Service service) { diff --git a/src/main/java/org/redkale/cluster/spi/ClusterAgent.java b/src/main/java/org/redkale/cluster/spi/ClusterAgent.java index b80f1b5af..9bf1cc9b0 100644 --- a/src/main/java/org/redkale/cluster/spi/ClusterAgent.java +++ b/src/main/java/org/redkale/cluster/spi/ClusterAgent.java @@ -202,10 +202,7 @@ public abstract class ClusterAgent { } } ClusterEntry entry = new ClusterEntry(ns, protocol, service); - if (entry.serviceName.endsWith(".")) { - return false; - } - return true; + return !entry.serviceName.endsWith("."); } protected void afterDeregister(NodeServer ns, String protocol) { diff --git a/src/main/java/org/redkale/convert/ConvertFactory.java b/src/main/java/org/redkale/convert/ConvertFactory.java index ba7a55649..eb9232a0c 100644 --- a/src/main/java/org/redkale/convert/ConvertFactory.java +++ b/src/main/java/org/redkale/convert/ConvertFactory.java @@ -763,7 +763,7 @@ public abstract class ConvertFactory { Type[] ts = ((ParameterizedType) type).getActualTypeArguments(); if (ts.length == 1) { Type t = ts[0]; - if (t == Boolean.class + return t == Boolean.class || t == Byte.class || t == Short.class || t == Character.class @@ -773,10 +773,7 @@ public abstract class ConvertFactory { || t == Double.class || t == String.class || rootFactory().findEncoder(t) != null - || ((t instanceof Class) && ((Class) t).isEnum())) { - return true; - } - return false; + || ((t instanceof Class) && ((Class) t).isEnum()); } } return false; diff --git a/src/main/java/org/redkale/convert/pb/ProtobufDynEncoder.java b/src/main/java/org/redkale/convert/pb/ProtobufDynEncoder.java index 53e8fa452..72be7edf6 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufDynEncoder.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufDynEncoder.java @@ -24,8 +24,6 @@ import org.redkale.util.*; */ public abstract class ProtobufDynEncoder extends ProtobufObjectEncoder { - protected final Class typeClass; - protected final ObjectEncoder objectEncoderSelf; // 动态字段: protected SimpledCoder xxxSimpledCoder; @@ -34,7 +32,6 @@ public abstract class ProtobufDynEncoder extends ProtobufObjectEncoder { protected ProtobufDynEncoder(ProtobufFactory factory, Type type, ProtobufObjectEncoder objectEncoderSelf) { super((Class) type); - this.typeClass = (Class) type; this.factory = factory; this.objectEncoderSelf = objectEncoderSelf; this.members = objectEncoderSelf.getMembers(); diff --git a/src/main/java/org/redkale/net/AsyncConnection.java b/src/main/java/org/redkale/net/AsyncConnection.java index e60af3094..adcc6a80a 100644 --- a/src/main/java/org/redkale/net/AsyncConnection.java +++ b/src/main/java/org/redkale/net/AsyncConnection.java @@ -1305,6 +1305,8 @@ public abstract class AsyncConnection implements Channel, AutoCloseable { }); return; } + default: + return; } } } diff --git a/src/main/java/org/redkale/net/Server.java b/src/main/java/org/redkale/net/Server.java index db0405174..0657a988b 100644 --- a/src/main/java/org/redkale/net/Server.java +++ b/src/main/java/org/redkale/net/Server.java @@ -404,19 +404,17 @@ public abstract class Server< final ProtocolServer oldServerChannel = this.serverChannel; ProtocolServer newServerChannel = null; InetSocketAddress addr0 = addr; - try { - newServerChannel = ProtocolServer.create(this.netprotocol, context, this.serverClassLoader); - this.resourceFactory.inject(newServerChannel); - newServerChannel.open(config); - newServerChannel.bind(addr, backlog); - SocketAddress localAddress = newServerChannel.getLocalAddress(); - if (localAddress instanceof InetSocketAddress) { - addr0 = (InetSocketAddress) localAddress; - } - newServerChannel.accept(application, this); - } catch (IOException e) { - throw e; + + newServerChannel = ProtocolServer.create(this.netprotocol, context, this.serverClassLoader); + this.resourceFactory.inject(newServerChannel); + newServerChannel.open(config); + newServerChannel.bind(addr, backlog); + SocketAddress localAddress = newServerChannel.getLocalAddress(); + if (localAddress instanceof InetSocketAddress) { + addr0 = (InetSocketAddress) localAddress; } + newServerChannel.accept(application, this); + context.updateServerAddress(addr0); this.address = context.serverAddress; this.serverChannel = newServerChannel; diff --git a/src/main/java/org/redkale/source/DataJdbcSource.java b/src/main/java/org/redkale/source/DataJdbcSource.java index 935eaca36..39fd8c93b 100644 --- a/src/main/java/org/redkale/source/DataJdbcSource.java +++ b/src/main/java/org/redkale/source/DataJdbcSource.java @@ -815,8 +815,6 @@ public class DataJdbcSource extends AbstractDataSqlSource { int c = Utility.sum(stmt2.executeBatch()); slowLog(s, sqls); return c; - } catch (SQLException se) { - throw se; } finally { conn.offerUpdateStatement(stmt2); } @@ -2199,7 +2197,7 @@ public class DataJdbcSource extends AbstractDataSqlSource { conn.setAutoCommit(true); prestmt = conn.prepareQueryStatement(sql); final ResultSet set = prestmt.executeQuery(); - boolean rs = set.next() ? (set.getInt(1) > 0) : false; + boolean rs = set.next() && (set.getInt(1) > 0); set.close(); conn.offerQueryStatement(prestmt); if (info.isLoggable(logger, Level.FINEST, sql)) { diff --git a/src/main/java/org/redkale/util/Utility.java b/src/main/java/org/redkale/util/Utility.java index fe2a496a8..dbf9afbda 100644 --- a/src/main/java/org/redkale/util/Utility.java +++ b/src/main/java/org/redkale/util/Utility.java @@ -5118,29 +5118,27 @@ public final class Utility { // return socket; // } // - public static String postHttpContent(String url) throws IOException { + public static String postHttpContent(String url) { return remoteHttpContent("POST", url, 0, null, null).toString(StandardCharsets.UTF_8); } - public static String postHttpContent(String url, int timeoutMs) throws IOException { + public static String postHttpContent(String url, int timeoutMs) { return remoteHttpContent("POST", url, timeoutMs, null, null).toString(StandardCharsets.UTF_8); } - public static String postHttpContent(String url, String body) throws IOException { + public static String postHttpContent(String url, String body) { return remoteHttpContent("POST", url, 0, null, body).toString(StandardCharsets.UTF_8); } - public static String postHttpContent(String url, int timeoutMs, String body) throws IOException { + public static String postHttpContent(String url, int timeoutMs, String body) { return remoteHttpContent("POST", url, timeoutMs, null, body).toString(StandardCharsets.UTF_8); } - public static String postHttpContent(String url, Map headers, String body) - throws IOException { + public static String postHttpContent(String url, Map headers, String body) { return remoteHttpContent("POST", url, 0, headers, body).toString(StandardCharsets.UTF_8); } - public static String postHttpContent(String url, int timeoutMs, Map headers, String body) - throws IOException { + public static String postHttpContent(String url, int timeoutMs, Map headers, String body) { return remoteHttpContent("POST", url, timeoutMs, headers, body).toString(StandardCharsets.UTF_8); } @@ -5171,38 +5169,36 @@ public final class Utility { return remoteHttpContent("POST", url, timeoutMs, headers, body).toString(charset.name()); } - public static byte[] postHttpBytesContent(String url) throws IOException { + public static byte[] postHttpBytesContent(String url) { return remoteHttpContent("POST", url, 0, null, null).toByteArray(); } - public static byte[] postHttpBytesContent(String url, int timeoutMs) throws IOException { + public static byte[] postHttpBytesContent(String url, int timeoutMs) { return remoteHttpContent("POST", url, timeoutMs, null, null).toByteArray(); } - public static byte[] postHttpBytesContent(String url, Map headers, String body) - throws IOException { + public static byte[] postHttpBytesContent(String url, Map headers, String body) { return remoteHttpContent("POST", url, 0, headers, body).toByteArray(); } - public static byte[] postHttpBytesContent(String url, int timeoutMs, Map headers, String body) - throws IOException { + public static byte[] postHttpBytesContent( + String url, int timeoutMs, Map headers, String body) { return remoteHttpContent("POST", url, timeoutMs, headers, body).toByteArray(); } - public static String getHttpContent(String url) throws IOException { + public static String getHttpContent(String url) { return remoteHttpContent("GET", url, 0, null, null).toString(StandardCharsets.UTF_8); } - public static String getHttpContent(String url, int timeoutMs) throws IOException { + public static String getHttpContent(String url, int timeoutMs) { return remoteHttpContent("GET", url, timeoutMs, null, null).toString(StandardCharsets.UTF_8); } - public static String getHttpContent(String url, Map headers, String body) throws IOException { + public static String getHttpContent(String url, Map headers, String body) { return remoteHttpContent("GET", url, 0, headers, body).toString(StandardCharsets.UTF_8); } - public static String getHttpContent(String url, int timeoutMs, Map headers, String body) - throws IOException { + public static String getHttpContent(String url, int timeoutMs, Map headers, String body) { return remoteHttpContent("GET", url, timeoutMs, headers, body).toString(StandardCharsets.UTF_8); } @@ -5225,41 +5221,38 @@ public final class Utility { return remoteHttpContent("GET", url, timeoutMs, headers, body).toString(charset.name()); } - public static byte[] getHttpBytesContent(String url) throws IOException { + public static byte[] getHttpBytesContent(String url) { return remoteHttpContent("GET", url, 0, null, null).toByteArray(); } - public static byte[] getHttpBytesContent(String url, int timeoutMs) throws IOException { + public static byte[] getHttpBytesContent(String url, int timeoutMs) { return remoteHttpContent("GET", url, timeoutMs, null, null).toByteArray(); } - public static byte[] getHttpBytesContent(String url, Map headers, String body) - throws IOException { + public static byte[] getHttpBytesContent(String url, Map headers, String body) { return remoteHttpContent("GET", url, 0, headers, body).toByteArray(); } - public static byte[] getHttpBytesContent(String url, int timeoutMs, Map headers, String body) - throws IOException { + public static byte[] getHttpBytesContent( + String url, int timeoutMs, Map headers, String body) { return remoteHttpContent("GET", url, timeoutMs, headers, body).toByteArray(); } - public static String remoteHttpContent(HttpClient client, String method, String url, Charset charset) - throws IOException { + public static String remoteHttpContent(HttpClient client, String method, String url, Charset charset) { return remoteHttpContentAsync(client, method, url, 0, null, null) .thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset)) .join(); } - public static String remoteHttpContent(HttpClient client, String method, String url, int timeoutMs, Charset charset) - throws IOException { + public static String remoteHttpContent( + HttpClient client, String method, String url, int timeoutMs, Charset charset) { return remoteHttpContentAsync(client, method, url, timeoutMs, null, null) .thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset)) .join(); } public static String remoteHttpContent( - HttpClient client, String method, String url, Charset charset, Map headers) - throws IOException { + HttpClient client, String method, String url, Charset charset, Map headers) { return remoteHttpContentAsync(client, method, url, 0, headers, null) .thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset)) .join(); @@ -5271,8 +5264,7 @@ public final class Utility { String url, Charset charset, Map headers, - String body) - throws IOException { + String body) { return remoteHttpContentAsync(client, method, url, 0, headers, body) .thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset)) .join(); @@ -5284,8 +5276,7 @@ public final class Utility { String url, int timeoutMs, Charset charset, - Map headers) - throws IOException { + Map headers) { return remoteHttpContentAsync(client, method, url, timeoutMs, headers, null) .thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset)) .join(); @@ -5298,8 +5289,7 @@ public final class Utility { int timeoutMs, Charset charset, Map headers, - String body) - throws IOException { + String body) { return remoteHttpContentAsync(client, method, url, timeoutMs, headers, body) .thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset)) .join(); @@ -5311,10 +5301,9 @@ public final class Utility { String url, Charset charset, Map headers, - String body) - throws IOException { + String body) { return remoteHttpContentAsync(client, method, url, 0, headers, body) - .thenApply(out -> out.toByteArray()) + .thenApply(ByteArrayOutputStream::toByteArray) .join(); } @@ -5324,10 +5313,9 @@ public final class Utility { String url, int timeoutMs, Charset charset, - Map headers) - throws IOException { + Map headers) { return remoteHttpContentAsync(client, method, url, timeoutMs, headers, null) - .thenApply(out -> out.toByteArray()) + .thenApply(ByteArrayOutputStream::toByteArray) .join(); } @@ -5338,27 +5326,29 @@ public final class Utility { int timeoutMs, Charset charset, Map headers, - String body) - throws IOException { + String body) { return remoteHttpContentAsync(client, method, url, timeoutMs, headers, body) - .thenApply(out -> out.toByteArray()) + .thenApply(ByteArrayOutputStream::toByteArray) .join(); } public static ByteArrayOutputStream remoteHttpContent( - String method, String url, Map headers, String body) throws IOException { + String method, String url, Map headers, String body) { return remoteHttpContent(method, url, 0, headers, body); } public static ByteArrayOutputStream remoteHttpContent( - String method, String url, int timeoutMs, Map headers, String body) - throws IOException { + String method, String url, int timeoutMs, Map headers, String body) { return remoteHttpContentAsync(method, url, timeoutMs, headers, body).join(); } public static ByteArrayOutputStream remoteHttpContent( - HttpClient client, String method, String url, int timeoutMs, Map headers, String body) - throws IOException { + HttpClient client, + String method, + String url, + int timeoutMs, + Map headers, + String body) { return remoteHttpContentAsync(client, method, url, timeoutMs, headers, body) .join(); } @@ -5548,38 +5538,40 @@ public final class Utility { } public static CompletableFuture postHttpBytesContentAsync(String url) { - return remoteHttpContentAsync("POST", url, 0, null, null).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("POST", url, 0, null, null).thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture postHttpBytesContentAsync( String url, Map respHeaders) { - return remoteHttpContentAsync("POST", url, 0, null, null, respHeaders).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("POST", url, 0, null, null, respHeaders) + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture postHttpBytesContentAsync(String url, int timeoutMs) { - return remoteHttpContentAsync("POST", url, timeoutMs, null, null).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("POST", url, timeoutMs, null, null).thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture postHttpBytesContentAsync( String url, int timeoutMs, Map respHeaders) { return remoteHttpContentAsync("POST", url, timeoutMs, null, null, respHeaders) - .thenApply(out -> out.toByteArray()); + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture postHttpBytesContentAsync( String url, Map headers, String body) { - return remoteHttpContentAsync("POST", url, 0, headers, body).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("POST", url, 0, headers, body).thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture postHttpBytesContentAsync( String url, Map headers, String body, Map respHeaders) { return remoteHttpContentAsync("POST", url, 0, headers, body, respHeaders) - .thenApply(out -> out.toByteArray()); + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture postHttpBytesContentAsync( String url, int timeoutMs, Map headers, String body) { - return remoteHttpContentAsync("POST", url, timeoutMs, headers, body).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("POST", url, timeoutMs, headers, body) + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture postHttpBytesContentAsync( @@ -5589,7 +5581,7 @@ public final class Utility { String body, Map respHeaders) { return remoteHttpContentAsync("POST", url, timeoutMs, headers, body, respHeaders) - .thenApply(out -> out.toByteArray()); + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture getHttpContentAsync(String url) { @@ -5718,37 +5710,40 @@ public final class Utility { } public static CompletableFuture getHttpBytesContentAsync(String url) { - return remoteHttpContentAsync("GET", url, 0, null, null).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("GET", url, 0, null, null).thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture getHttpBytesContentAsync( String url, Map respHeaders) { - return remoteHttpContentAsync("GET", url, 0, null, null, respHeaders).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("GET", url, 0, null, null, respHeaders) + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture getHttpBytesContentAsync(String url, int timeoutMs) { - return remoteHttpContentAsync("GET", url, timeoutMs, null, null).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("GET", url, timeoutMs, null, null).thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture getHttpBytesContentAsync( String url, int timeoutMs, Map respHeaders) { return remoteHttpContentAsync("GET", url, timeoutMs, null, null, respHeaders) - .thenApply(out -> out.toByteArray()); + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture getHttpBytesContentAsync( String url, Map headers, String body) { - return remoteHttpContentAsync("GET", url, 0, headers, body).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("GET", url, 0, headers, body).thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture getHttpBytesContentAsync( String url, Map headers, String body, Map respHeaders) { - return remoteHttpContentAsync("GET", url, 0, headers, body, respHeaders).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("GET", url, 0, headers, body, respHeaders) + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture getHttpBytesContentAsync( String url, int timeoutMs, Map headers, String body) { - return remoteHttpContentAsync("GET", url, timeoutMs, headers, body).thenApply(out -> out.toByteArray()); + return remoteHttpContentAsync("GET", url, timeoutMs, headers, body) + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture getHttpBytesContentAsync( @@ -5758,7 +5753,7 @@ public final class Utility { String body, Map respHeaders) { return remoteHttpContentAsync("GET", url, timeoutMs, headers, body, respHeaders) - .thenApply(out -> out.toByteArray()); + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture getHttpBytesContentAsync( @@ -5769,7 +5764,7 @@ public final class Utility { String body, Map respHeaders) { return remoteHttpContentAsync(client, "GET", url, timeoutMs, headers, body, respHeaders) - .thenApply(out -> out.toByteArray()); + .thenApply(ByteArrayOutputStream::toByteArray); } public static CompletableFuture remoteHttpContentAsync(