JDK10 compatibility fixed #1367

pull/1423/head
Nikita 7 years ago
parent 762c61ef2e
commit dd13ac99e2

@ -30,6 +30,7 @@ import org.redisson.connection.ConnectionManager;
import org.redisson.connection.DnsAddressResolverGroupFactory; import org.redisson.connection.DnsAddressResolverGroupFactory;
import org.redisson.connection.AddressResolverGroupFactory; import org.redisson.connection.AddressResolverGroupFactory;
import org.redisson.connection.ReplicatedConnectionManager; import org.redisson.connection.ReplicatedConnectionManager;
import org.redisson.misc.URIBuilder;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
@ -96,6 +97,10 @@ public class Config {
public Config() { public Config() {
} }
static {
URIBuilder.patchUriObject();
}
public Config(Config oldConf) { public Config(Config oldConf) {
setUseLinuxNativeEpoll(oldConf.isUseLinuxNativeEpoll()); setUseLinuxNativeEpoll(oldConf.isUseLinuxNativeEpoll());
setExecutor(oldConf.getExecutor()); setExecutor(oldConf.getExecutor());

@ -19,9 +19,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
@ -125,101 +122,62 @@ public class ConfigSupport {
private ObjectMapper jsonMapper = createMapper(null, null); private ObjectMapper jsonMapper = createMapper(null, null);
private ObjectMapper yamlMapper = createMapper(new YAMLFactory(), null); private ObjectMapper yamlMapper = createMapper(new YAMLFactory(), null);
private void patchUriObject() throws IOException {
patchUriField("lowMask", "L_DASH");
patchUriField("highMask", "H_DASH");
}
private void patchUriField(String methodName, String fieldName)
throws IOException {
try {
Method lowMask = URI.class.getDeclaredMethod(methodName, String.class);
lowMask.setAccessible(true);
Long lowMaskValue = (Long) lowMask.invoke(null, "-_");
Field lowDash = URI.class.getDeclaredField(fieldName);
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(lowDash, lowDash.getModifiers() & ~Modifier.FINAL);
lowDash.setAccessible(true);
lowDash.setLong(null, lowMaskValue);
} catch (Exception e) {
throw new IOException(e);
}
}
public <T> T fromJSON(String content, Class<T> configType) throws IOException { public <T> T fromJSON(String content, Class<T> configType) throws IOException {
patchUriObject();
return jsonMapper.readValue(content, configType); return jsonMapper.readValue(content, configType);
} }
public <T> T fromJSON(File file, Class<T> configType) throws IOException { public <T> T fromJSON(File file, Class<T> configType) throws IOException {
patchUriObject();
return fromJSON(file, configType, null); return fromJSON(file, configType, null);
} }
public <T> T fromJSON(File file, Class<T> configType, ClassLoader classLoader) throws IOException { public <T> T fromJSON(File file, Class<T> configType, ClassLoader classLoader) throws IOException {
patchUriObject();
jsonMapper = createMapper(null, classLoader); jsonMapper = createMapper(null, classLoader);
return jsonMapper.readValue(file, configType); return jsonMapper.readValue(file, configType);
} }
public <T> T fromJSON(URL url, Class<T> configType) throws IOException { public <T> T fromJSON(URL url, Class<T> configType) throws IOException {
patchUriObject();
return jsonMapper.readValue(url, configType); return jsonMapper.readValue(url, configType);
} }
public <T> T fromJSON(Reader reader, Class<T> configType) throws IOException { public <T> T fromJSON(Reader reader, Class<T> configType) throws IOException {
patchUriObject();
return jsonMapper.readValue(reader, configType); return jsonMapper.readValue(reader, configType);
} }
public <T> T fromJSON(InputStream inputStream, Class<T> configType) throws IOException { public <T> T fromJSON(InputStream inputStream, Class<T> configType) throws IOException {
patchUriObject();
return jsonMapper.readValue(inputStream, configType); return jsonMapper.readValue(inputStream, configType);
} }
public String toJSON(Config config) throws IOException { public String toJSON(Config config) throws IOException {
patchUriObject();
return jsonMapper.writeValueAsString(config); return jsonMapper.writeValueAsString(config);
} }
public <T> T fromYAML(String content, Class<T> configType) throws IOException { public <T> T fromYAML(String content, Class<T> configType) throws IOException {
patchUriObject();
return yamlMapper.readValue(content, configType); return yamlMapper.readValue(content, configType);
} }
public <T> T fromYAML(File file, Class<T> configType) throws IOException { public <T> T fromYAML(File file, Class<T> configType) throws IOException {
patchUriObject();
return yamlMapper.readValue(file, configType); return yamlMapper.readValue(file, configType);
} }
public <T> T fromYAML(File file, Class<T> configType, ClassLoader classLoader) throws IOException { public <T> T fromYAML(File file, Class<T> configType, ClassLoader classLoader) throws IOException {
patchUriObject();
yamlMapper = createMapper(new YAMLFactory(), classLoader); yamlMapper = createMapper(new YAMLFactory(), classLoader);
return yamlMapper.readValue(file, configType); return yamlMapper.readValue(file, configType);
} }
public <T> T fromYAML(URL url, Class<T> configType) throws IOException { public <T> T fromYAML(URL url, Class<T> configType) throws IOException {
patchUriObject();
return yamlMapper.readValue(url, configType); return yamlMapper.readValue(url, configType);
} }
public <T> T fromYAML(Reader reader, Class<T> configType) throws IOException { public <T> T fromYAML(Reader reader, Class<T> configType) throws IOException {
patchUriObject();
return yamlMapper.readValue(reader, configType); return yamlMapper.readValue(reader, configType);
} }
public <T> T fromYAML(InputStream inputStream, Class<T> configType) throws IOException { public <T> T fromYAML(InputStream inputStream, Class<T> configType) throws IOException {
patchUriObject();
return yamlMapper.readValue(inputStream, configType); return yamlMapper.readValue(inputStream, configType);
} }
public String toYAML(Config config) throws IOException { public String toYAML(Config config) throws IOException {
patchUriObject();
return yamlMapper.writeValueAsString(config); return yamlMapper.writeValueAsString(config);
} }

@ -15,6 +15,9 @@
*/ */
package org.redisson.misc; package org.redisson.misc;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -40,6 +43,31 @@ public class URIBuilder {
return URI.create(uri.replace(s, "[" + s + "]")); return URI.create(uri.replace(s, "[" + s + "]"));
} }
public static void patchUriObject() {
try {
patchUriField(35184372088832L, "L_DASH");
patchUriField(2147483648L, "H_DASH");
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
private static void patchUriField(Long maskValue, String fieldName)
throws IOException {
try {
Field field = URI.class.getDeclaredField(fieldName);
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.setAccessible(true);
field.setLong(null, maskValue);
} catch (Exception e) {
throw new IOException(e);
}
}
public static boolean isValidIP(String host) { public static boolean isValidIP(String host) {
if (ipv4Pattern.matcher(host).matches()) { if (ipv4Pattern.matcher(host).matches()) {
return true; return true;

Loading…
Cancel
Save