Tag Archives: Pit

[Solved] stream Convert list to map Error: java.lang.IllegalStateException: Duplicate key

I background

In many scenarios, the data of List needs to be transformed into the key-value pairs of Map scenarios to facilitate quick query data. For example: the need to query the corresponding person name details scenario according to the work number. There are two kinds of scenarios, the first one is to query the database once by each work number, which is obviously not reasonable because it is not good for DB pressure and connection. The second will be a collection of work number (need to consider the volume of data scenarios, Oracle supports a maximum of one thousand, mysql, although no online, but consider the performance and memory consumption need to consider the upper limit recommended 1000 below), the next is the second way to expand.

Translated with www.DeepL.com/Translator (free version)

II Development practice

List<User> userList = new ArrayList<>();

userList.add(User.builder().id(123).name("TEST123").build());

userList.add(User.builder().id(1231).name("TEST1231").build());

userList.add(User.builder().id(1232).name("TEST1232").build());

userList.add(User.builder().id(1233).name("TEST1233").build());

userList.add(User.builder().id(1234).name("TEST1234").build());

1.The stream implementation was not available before Java 1.8

Map<String, Long> idNameMap = new HashMap<String, Long>();

for(User user : userList ){

     idNameMap.put(user.getName(),  user.getId());

}

return idNameMap ;

2.Java 1.8 onwards supports stream implementation

return userList.stream().collect(Collectors.toMap(User::getName, User::getId);

III Existing problems

If you use the 2.1 way, the possible problems, if there are two data with the same name in the data, it will report an error java.lang.IllegalStateException: Duplicate key.

When using stream stream, it will not overwrite the data directly like the above way, but will report an error. So it needs to be optimized as

return userList.stream().collect(Collectors.toMap(User::getName, User::getId , (entity1, entity2) -> entity1);

It can solve the problem of error reporting.

Import error, failed to import the debug version of PYD

Today, I used swig to encapsulate the underlying C + + library. After the result was encapsulated, release was OK. However, in the debug mode, the import failed all the time, indicating that the module could not be found. Why did I fail when I had PYD?

After troubleshooting, PYD in the original debug mode must be added_ d

The result is to add_ D is solved; For example_ Somelib.pyd should be_ someLib_ d. PYD, so Python can import.

Modify cmakelists.txt to ensure that it is added in debug mode_ d

set(CMAKE_DEBUG_POSTFIX _d)
set_target_properties(${target_name} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})

MYSQL Safe Upgraded Error: You are using safe update mode and you tried to update

Error:

21:55:14 update users set realname=‘Lisi2’ where username=‘ls’ Error
Code: 1175. You are using safe update mode and you tried to update a
table without a WHERE that uses a KEY column. To disable safe mode,
toggle the option in Preferences -> SQL Editor and reconnect. 0.000
sec

Solution:
Execution of this statement will result in: SET SQL_SAFE_UPDATES=0;

Error report of windows system running UMI project

Error code:



events.js:291
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot mix BigInt and other types, use explicit conversions
    at FSWatcher._hasReadPermissions (C:\Users\3123\node_modules\chokidar\index.js:775:36)
    at WatchHelper.filterPath (C:\Users\3123\node_modules\chokidar\index.js:191:16)
    at ReaddirpStream.fileFilter [as _fileFilter] (C:\Users\3123\node_modules\chokidar\lib\nodefs-handler.js:405:29)
    at ReaddirpStream._read (C:\Users\3123\node_modules\readdirp\index.js:141:85)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (C:\Users\3123\node_modules\chokidar\index.js:592:10)
    at ReaddirpStream.NodeFsHandler._boundHandleError (C:\Users\3123\node_modules\chokidar\lib\nodefs-handler.js:252:43)
    at ReaddirpStream.emit (events.js:314:20)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
npm ERR! code ELIFECYCLE
npm ERR! errno 1

npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] qa script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.    

npm ERR! A complete log of this run can be found in: 

Solution:
Enter node_ Modify the 775 line of the modules/chokidar/index.js file as follows

Stats.mode is bigint, when using & amp; This error will be reported when adding parseInt (stats. Mode)

_hasReadPermissions(stats) {
if (this.options.ignorePermissionErrors) return true;

const st = (stats && parseInt(stats.mode)) & 0o777;
const it = parseInt(st.toString(8)[0], 10);
return Boolean(4 & it);
}

“26696;” 332581; https://github.com/umijs/umi/issues/2769

How to Fix java.net.ConnectException: Connection refused: connect

java.net.ConnectException: Connection refused: connect

1. Error as above.
2. Reasons and Solutions:
 
1) The port number is occupied: kill the process occupying the port number (generally 8080) and release the port; Shut down the Tomcat server completely, or restart the project.
2) Use the following command to check the maximum number of processes allowed on the server: ulimit-u. If this value is set to a lower value, such as 1024, then increase it to 131072 or unrestricted with the following value: ulimit-u 131072 or ulimit-u unrestricted.
 
3) Client and server, either or both of which are not in the network.
They may not be connected to a LAN or the Internet or any other network, in which case Java will be thrown
The client “java.net.ConnectException:Connection refused” exception.

4) server not running
The server is down but not running. In this case, you will also get java.net.ConnectException: connection refused error. Ping to check if the server is running and listening on the port.

5) server running but not listening port, client trying to connect.
The server is running but listening on a different port. Verify the configuration. If you are working on a large project and have a hierarchical configuration file, it may be the default configuration or some other Settings overwrite your correct Settings.
 
6) Host port combination is not allowed to use firewall
Almost every corporate network is protected by a firewall. If you are connecting to other corporate networks, such as in any electronic trading system, you need to improve the firewall
Both parties are required to ensure that they allow each other’s IP address and port number. If the firewall is not allowed to connect, will also receive the same java.net.ConnectException:Java connection refused to abnormal in application.
 
7) Incorrect host port combination.
The host port combination provided is incorrect, or the earlier host port combination on the server side has changed. Check the latest configuration on both the client and server sides.
 
8) The protocol in the connection string is incorrect
TCP is the basis for many advanced protocols, including HTTP, RMI, and so on. Through the connection string, you need to make sure that you pass the correct protocol that the server expects. For example, if the server is exposed, a service that passes through RMI instead of a connection string should start with RMI: //.
 
 
3. My situation:
, my reason is relatively simple, which probably belongs to the 5th, 7th and 8th points above, but the configuration is not correct anyway. I just miswrote the IP address of the server where the database is located.

spring.datasource.url=jdbc:mysql://数据库所在服务器IP:3306/gaei_ms?useUnicode=true&characterEncoding=utf-8&useSSL=false

———————————————————————————————
July 4, 2019:
From the comments:
“The same can happen if all parameters are not added to the comment.”
Join the article, for reference, also very grateful to this friend: ‘Seven.
 
 
 
Reference: https://javarevisited.blogspot.com/2013/02/java-net-ConnectException-Connection-refused.html

Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar (default) on project

packing error :

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:jar (default) on project tencentlvb: MavenReportException: Error while creating archive: 
[ERROR] Exit code: 1 - D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\enums\DomainTypeEnum.java:12: ����: δ֪���: date
[ERROR]  * @date 2020/2/21
[ERROR]    ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\enums\DomainTypeEnum.java:13: ����: δ֪���: time
[ERROR]  * @time 14:49
[ERROR]    ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\enums\EventTypeEnum.java:10: ����: δ֪���: date
[ERROR]  * @date 2020/2/23
[ERROR]    ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\enums\EventTypeEnum.java:11: ����: δ֪���: time
[ERROR]  * @time 20:13
[ERROR]    ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\enums\IsDelayLiveEnum.java:13: ����: δ֪���: date
[ERROR]  * @date 2020/2/21
[ERROR]    ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\enums\IsDelayLiveEnum.java:14: ����: δ֪���: time
[ERROR]  * @time 14:58
[ERROR]    ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\enums\PlayTypeEnum.java:14: ����: δ֪���: date
[ERROR]  * @date 2020/2/21
[ERROR]    ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\enums\PlayTypeEnum.java:15: ����: δ֪���: time
[ERROR]  * @time 14:53
[ERROR]    ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:47: ����: ��Ҫ��ʶ��
[ERROR]      * @param: domainName ���� ����
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:48: ����: ��Ҫ��ʶ��
[ERROR]      * @param: domainTypeEnum �������� ����
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:49: ����: ��Ҫ��ʶ��
[ERROR]      * @param: playTypeEnum ������������ Ĭ�Ϲ���
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:50: ����: ��Ҫ��ʶ��
[ERROR]      * @param: isDelayLiveEnum �Ƿ�����ֱ�� Ĭ�Ϸ�
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:52: ����: �����г����﷨����
[ERROR]      * @exception 
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:54: ����: δ֪���: date
[ERROR]      * @date 2020/2/21
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:56: ����: domainNameû�� @param
[ERROR]     public AddLiveDomainResponse addRealmName(String domainName, DomainTypeEnum domainTypeEnum, PlayTypeEnum playTypeEnum, IsDelayLiveEnum isDelayLiveEnum) {
[ERROR]                                  ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:56: ����: domainTypeEnumû�� @param
[ERROR]     public AddLiveDomainResponse addRealmName(String domainName, DomainTypeEnum domainTypeEnum, PlayTypeEnum playTypeEnum, IsDelayLiveEnum isDelayLiveEnum) {
[ERROR]                                  ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:56: ����: playTypeEnumû�� @param
[ERROR]     public AddLiveDomainResponse addRealmName(String domainName, DomainTypeEnum domainTypeEnum, PlayTypeEnum playTypeEnum, IsDelayLiveEnum isDelayLiveEnum) {
[ERROR]                                  ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:56: ����: isDelayLiveEnumû�� @param
[ERROR]     public AddLiveDomainResponse addRealmName(String domainName, DomainTypeEnum domainTypeEnum, PlayTypeEnum playTypeEnum, IsDelayLiveEnum isDelayLiveEnum) {
[ERROR]                                  ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:76: ����: ��Ҫ��ʶ��
[ERROR]      * @param: domainName ���� ����
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:77: ����: ��Ҫ��ʶ��
[ERROR]      * @param: domainTypeEnum �������� ����
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:78: ����: ��Ҫ��ʶ��
[ERROR]      * @param: playTypeEnum ������������ Ĭ�Ϲ���
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:80: ����: �����г����﷨����
[ERROR]      * @exception
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:82: ����: δ֪���: date
[ERROR]      * @date 2020/2/21
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:84: ����: domainNameû�� @param
[ERROR]     public AddLiveDomainResponse addRealmName(String domainName, DomainTypeEnum domainTypeEnum, PlayTypeEnum playTypeEnum) {
[ERROR]                                  ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:84: ����: domainTypeEnumû�� @param
[ERROR]     public AddLiveDomainResponse addRealmName(String domainName, DomainTypeEnum domainTypeEnum, PlayTypeEnum playTypeEnum) {
[ERROR]                                  ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:84: ����: playTypeEnumû�� @param
[ERROR]     public AddLiveDomainResponse addRealmName(String domainName, DomainTypeEnum domainTypeEnum, PlayTypeEnum playTypeEnum) {
[ERROR]                                  ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:101: ����: ��Ҫ��ʶ��
[ERROR]      * @param: domainName ���� ����
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:102: ����: ��Ҫ��ʶ��
[ERROR]      * @param: domainTypeEnum �������� ����
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:103: ����: ��Ҫ��ʶ��
[ERROR]      * @param: playTypeEnum ������������
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:105: ����: �����г����﷨����
[ERROR]      * @exception
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:107: ����: δ֪���: date
[ERROR]      * @date 2020/2/21
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:109: ����: domainNameû�� @param
[ERROR]     public AddLiveDomainResponse addRealmName(String domainName, DomainTypeEnum domainTypeEnum) {
[ERROR]                                  ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:109: ����: domainTypeEnumû�� @param
[ERROR]     public AddLiveDomainResponse addRealmName(String domainName, DomainTypeEnum domainTypeEnum) {
[ERROR]                                  ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:124: ����: ��Ҫ��ʶ��
[ERROR]      * @param: pushDomain
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:125: ����: ��Ҫ��ʶ��
[ERROR]      * @param: appName
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:126: ����: ��Ҫ��ʶ��
[ERROR]      * @param: streamName
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:127: ����: @return û��˵��
[ERROR]      * @return
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:128: ����: �����г����﷨����
[ERROR]      * @exception 
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:130: ����: δ֪���: date
[ERROR]      * @date 2020/2/23
[ERROR]        ^
[ERROR] D:\workspace\tencentlvb\src\main\java\com\tangjianghua\tencentlvb\live\TencentLvbLiveClient.java:132: ����: domainû�� @param
[ERROR]     public DescribeLiveStreamStateResponse describeLiveStreamState(String domain, String appName, String streamName){
[ERROR]                                            ^
[ERROR] 
.
.
.

reason :javac test does not pass

solution: skip the javac detection

add command

-Dmaven.javadoc.skip=true