# java 中错误总结
# rocketMq
# 与 springboot 兼容问题
An attempt was made to call a method that does not exist. The attempt was made from the following location:
com.alibaba.cloud.stream.binder.rocketmq.RocketMQMessageChannelBinder.createProducerMessageHandler(RocketMQMessageChannelBinder.java:172)
The following method did not exist:
org.springframework.integration.channel.AbstractMessageChannel.getChannelInterceptors()Ljava/util/List;
The method's class, org.springframework.integration.channel.AbstractMessageChannel, is available from the following locations:
jar:file:/C:/Users/admin/.gradle/caches/modules-2/files-2.1/org.springframework.integration/spring-integration-core/5.3.2.RELEASE/1f44e4fc3209233fe4ab75934c3ab151eb88474f/spring-integration-core-5.3.2.RELEASE.jar!/org/springframework/integration/channel/AbstractMessageChannel.class
The class hierarchy was loaded from the following locations:
org.springframework.integration.channel.AbstractMessageChannel: file:/C:/Users/admin/.gradle/caches/modules-2/files-2.1/org.springframework.integration/spring-integration-core/5.3.2.RELEASE/1f44e4fc3209233fe4ab75934c3ab151eb88474f/spring-integration-core-5.3.2.RELEASE.jar
org.springframework.integration.context.IntegrationObjectSupport: file:/C:/Users/admin/.gradle/caches/modules-2/files-2.1/org.springframework.integration/spring-integration-core/5.3.2.RELEASE/1f44e4fc3209233fe4ab75934c3ab151eb88474f/spring-integration-core-5.3.2.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.springframework.integration.channel.AbstractMessageChannel
2
3
4
5
6
7
8
9
10
11
12
13
14
15
版本匹配
rocketMq 用的2.几,那么 springboot 也就只能 2.几;
不能出现 rocketMq 用的 2.2.0,而 springboot 用的 2.3 及其以上
# java 开发常犯的 10 个错误
# 1、Array 转 ArrayList
不再赘述
# 2、判断一个数组是否包含某个值
Arrays.asList(arr).contains(targetValue);
# 3、在循环内部删除 List 中的一个元素
ArrayList<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c","d"));
for (int i = 0; i < list.size(); i++) {
list.remove(i);
}
System.out.println(list);
2
3
4
5
ArrayList<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c","d"));
for (String s : list) {
if (s.equals("a")){
list.remove(s);
}
}
2
3
4
5
6
上面会抛出ConcurrentModificationException异常。
然而接下来的代码却是 OK 的:
ArrayList<String> list = new ArrayList<String>(Arrays.asList("a", "b", "c","d"));
Iterator<String> iter = list.iterator();
while (iter.hasNext()) {
String s = iter.next();
if (s.equals("a")) {
iter.remove();
}
}
2
3
4
5
6
7
8
下面的代码也不会有问题CopyOnWriteArrayList
List<String> list = new CopyOnWriteArrayList<>();
for (String s : list) {
list.remove(s);
2
3
next()方法需要在remove()方法之前被调用,在 foreach 循环里,编译器会在删除元素操作后调用 next 方法,这导致了 ConcurrentModificationException 异常。更多详细信息,可以查看 ArrayList.iterator()的源码。
当然 java8 中也已经新增如下方法,很好用:
resultList.removeIf(treeVo -> blankBuildingsCompanyIds.contains(treeVo.getId()));
# 4、HashTable 与 HashMap
# 6、访问级别
开发人员经常使用 public 修饰类字段,虽然这很容易让别人直接通过引用获取该字段的值,但这是一个不好的设计。根据经验,应该尽可能的降低成员属性的访问级别。
# 7、ArrayList 和 LinkedList
为什么开发人员经常使用 ArrayList 和 LinkedList,却不知道他们之间的区别,因为它们看起来很像。然而它们之间有着巨大的性能差异。简单的说,如果有大量的增加删除操作并且没有很多的随机访问元素的操作,应该首选 LinkedList。
# 9、父类和子类的构造方法
是因为父类的默认构造方法未定义。在 Java 中,如果一个类没有定义构造方法,编译器会默认插入一个无参数的构造方法;但是如果一个构造方法在父类中已定义,在这种情况,编译器是不会自动插入一个默认的无参构造方法,
# 前端下载文件
Could not find acceptable representation
只需将接口返回类型改为void
# 异常排查
# java.lang.IllegalArgumentException:Input == null
缺少文件路径,或者路径不对
# Netty
# Netty作为客户端
ws://es.sunshy.cn:8089?userGuid=20210813095117260_9f46d7f0bdec4c3fb934a0391b4b811c&onlineGuid=fd17b0b268dc45b9b7d6316a1be4bc73&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VyR3VpZCI6IjIwMjEwODEzMDk1MTE3MjYwXzlmNDZkN2YwYmRlYzRjM2ZiOTM0YTAzOTFiNGI4MTFjIiwiVXNlck5hbWUiOiLmtYvor5UwODEyIiwiUm9sZUNvZGUiOiI5OSIsIk9ubGluZUd1aWQiOiJmZDE3YjBiMjY4ZGM0NWI5YjdkNjMxNmExYmU0YmM3MyIsIm5iZiI6MTYyODgzODgyNywiZXhwIjoxNjI4ODQyNDI3LCJpc3MiOiJHZWxhbmRlIiwiYXVkIjoiR0VTTVAifQ.QdhcrwgwAozp3H_ZZGJF1yIukQIfHDaLRewZlxCIOyE&subscribe=true
在netty中,这个请求这个地址,服务器会报400【400 Bad Request】错误,原因就是地址的问题,在问号【?】的前面必须是【/】
即地址为:
ws://es.sunshy.cn:8089/?userGuid=20210813095117260_9f46d7f0bdec4c3fb934a0391b4b811c&onlineGuid=fd17b0b268dc45b9b7d6316a1be4bc73&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VyR3VpZCI6IjIwMjEwODEzMDk1MTE3MjYwXzlmNDZkN2YwYmRlYzRjM2ZiOTM0YTAzOTFiNGI4MTFjIiwiVXNlck5hbWUiOiLmtYvor5UwODEyIiwiUm9sZUNvZGUiOiI5OSIsIk9ubGluZUd1aWQiOiJmZDE3YjBiMjY4ZGM0NWI5YjdkNjMxNmExYmU0YmM3MyIsIm5iZiI6MTYyODgzODgyNywiZXhwIjoxNjI4ODQyNDI3LCJpc3MiOiJHZWxhbmRlIiwiYXVkIjoiR0VTTVAifQ.QdhcrwgwAozp3H_ZZGJF1yIukQIfHDaLRewZlxCIOyE&subscribe=true
wss://domain?access_token...is not a valid URL. The path component must start with a / and not a ?. This means that the request is invalid which can explain the response of 400 Bad Request.
The URL must be at least wss://domain/?access_token... (i.e. a / before the ?) but maybe the rest of the URL is unexpected by the server too. Please check the actual requirements of the server.