最近在插件 Api Generator Plus 上新增了一个功能,弹窗显示本机所有网络接口(其中筛选掉回环接口、子接口、未运行的接口)名称和ip。效果如下
开发测试使用的 IntelliJ Platform Plugin SDK 版本是 IntelliJ IDEA Community Edition IC-191.8026.42 (2019.1.4) 如下图:
开发完成,打包发布v1.0.14版本后。我在 IntelliJ IDEA 2023.2 (Ultimate Edition) 中升级测试了一下,结果成这样了😱😱😱
过滤网络接口的代码失效了,过滤代码如下:
完整代码如下:
package site.forgus.plugins.apigeneratorplus.util;
import org.jetbrains.annotations.Nullable;
import site.forgus.plugins.apigeneratorplus.model.NetInterfaceWrap;
import java.net.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
/**
* @author limaoxu
* @date 2024-7-17 01:40:03
*/
public class NetworkUtil {
@Nullable
public static List<NetInterfaceWrap> getAll() {
try {
boolean checkedInterface = false;
List<NetInterfaceWrap> netInterfaceWraps = new ArrayList<>();
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = allNetInterfaces.nextElement();
// 去除回环接口,子接口,未运行和接口
if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
continue;
}
NetInterfaceWrap wrap = new NetInterfaceWrap();
String displayName = netInterface.getDisplayName();
wrap.setDisplayName(displayName);
if (!checkedInterface && (!displayName.contains("Virtual") && !displayName.contains("Adapter"))) {
checkedInterface = true;
wrap.setChecked(true);
}
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress ip = addresses.nextElement();
if (ip != null) {
// ipv4
if (ip instanceof Inet4Address) {
wrap.setIpV4(ip.getHostAddress());
}
}
}
netInterfaceWraps.add(wrap);
}
return netInterfaceWraps;
} catch (SocketException e) {
//捕获异常
}
return null;
}
}
开始我以为是在高版本 IDEA 中不兼容导致的,于是我就更换 IntelliJ Platform Plugin SDK 版本,使用 IntelliJ IDEA Community Edition IC-222.4554.10(2022.2.5) 版本进行沙箱测试,出乎意料的是结果竟然正常!!!
由于不同IDEA版本使用的内置jre版本是不同的,于是我怀疑是不是JDK版本的问题(这里思路有点走偏了),2019.1.4 JDK版本是11, 2022.2.5 JDK版本是17, 于是修改 Plugin SDK (2022.2.5) 内置 JDK 版本为11测试。
修改Plugin SDK 内置 JDK 版本方法如下:
结果还是正常的!!!
没办法,我只能又将 Plugin SDK 版本修改为与出问题的版本 2023.3.2 保持一致测试,结果还是正常的!!!
到这里我实在想不出是哪里的原因了。没道理同一个版本正常使用和作为沙箱环境使用表现却不一致。然后我就想放弃了。只把这个问题记录一下就算了。
结果在记录过程中我发现正常使用的2023.3.2版本安装了很多非内置插件,而沙箱环境启动时我选择了不导入配置,所以就只有测试插件一个非内置插件。哎,我就想会不会是装了非内置插件的问题。
于是我用了另外的正常使用版本测试,正好电脑以前装的2022.2.5版本还没卸载,因为正常使用过一段时间,所以也装了很多非内置插件。不出意外,结果是有异常:
回看上面的多项测试结果,这里基本上就确定了,是安装了某个非内置插件导致的。
不过正好电脑以前装的 2019.3.2 版本还在,也装了很多插件,就再次测试了一次。这次结果还是有异常!!!
好了,问题找到了,是第三方插件导致的异常出现,由于装的插件挺多的(结尾有贴),我也不想挨个卸载测试是哪个插件导致的。那就想其他办法修改代码解决吧。
出异常的 IntelliJ IDEA 版本及插件列表:
IntelliJ IDEA 2019.3.2 (Ultimate Edition)
Build #IU-193.6015.39, built on January 21, 2020
Licensed to https://zhile.io
You have a perpetual fallback license for this version
Subscription is active until July 8, 2089
Runtime version: 11.0.5+10-b520.30 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 2010M
Cores: 4
Registry: java.completion.argument.hints.internal=false
Non-Bundled Plugins: AceJump, BashSupport, CMD Support, CheckStyle-IDEA, CopyRestUrl, Dart, GenerateSerialVersionUID, GsonFormat, GsonFormatPlus, Lombook Plugin, MavenRunHelper, MyBatisLogPlugin, Pythonid, String Manipulation, YapiUpload, cn.wuzhizhan.plugin.mybatis, com.alibabacloud.intellij.cosy, com.alibabacloud.intellij.toolkit-intellij, org.jetbrains.kotlin, com.baomidou.plugin.idea.mybatisx, com.ccnode.codegenerator.MyBatisCodeHelperPro, com.bruce.intellijplugin.generatesetter, com.ccnode.codegenerator.mybatis.generator, com.chuntung.plugin.mybatisbuilder, com.codota.csp.intellij, com.ctfin.idea.mybatis-generator, com.dengzii.plugin.converter, com.dubreuia, com.github.holgerbrandl.pasteimages/, com.github.redfoos.logstash-intellij-plugin, com.github.syuchan1005.npmscriptrunner, com.intellij.bigdatatools, com.intellij.ideolog, com.intellij.lang.jsgraphql, com.itangcent.idea.plugin.easy-yapi, com.jetbrains.packagesearch.intellij-plugin, com.robohorse.robopojogenerator, com.starxg.mybatis-log-plugin-free, com.suiyiwen.plugin.idea.apidoc, com.sunq.action.WebStormPX2REMTools, com.thoughtworks.gauge, de.netnexus.camelcaseplugin, eu.bolt.toolkit.intellij-plugin, ink.organics.pojo2json, izhangzhihao.rainbow.brackets, net.vektah.codeglance, net.vektah.codeglance2, org.arxing.chinese_converter, org.jetbrains.idea.grammar, org.jetbrains.plugins.hocon, org.jetbrains.plugins.vue, ru.adelf.idea.dotenv, site.forgus.plugins.api-generator, site.forgus.plugins.api-generator-plus
IntelliJ IDEA 2022.2.5 (Ultimate Edition)
Build #IU-222.4554.10, built on March 15, 2023
Licensed to signup scooter
You have a perpetual fallback license for this version.
Subscription is active until August 1, 2025.
Runtime version: 17.0.6+7-b469.82 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2044M
Cores: 4
Non-Bundled Plugins:
net.vektah.codeglance2 (1.5.5)
de.netnexus.camelcaseplugin (3.0.12)
dev.meanmail.plugin.nginx-intellij-plugin (2022.1.1)
com.robohorse.robopojogenerator (2.4.0)
com.github.redfoos.logstash-intellij-plugin (0.8.0)
CMD Support (1.0.5)
com.starxg.mybatis-log-plugin-free (1.3.0)
com.github.holgerbrandl.pasteimages/ (1.2.11)
com.nasller.CodeGlancePro (1.6.0)
mobi.hsz.idea.gitignore (4.4.2)
com.intellij.ideolog (222.1.0.0)
com.ctfin.idea.mybatis-generator (1.1.1)
com.ccnode.codegenerator.mybatis.generator (2018.12.14)
GenerateSerialVersionUID (3.0.3)
CopyRestUrl (1.5)
org.arxing.chinese_converter (1.0.1)
GsonFormatPlus (1.6.1)
org.jetbrains.idea.grammar (2021.1.2)
String Manipulation (9.7.1)
Dart (222.4582)
org.jetbrains.plugins.vue (222.4554.15)
com.jetbrains.plugins.jade (222.4459.16)
com.dmarcotte.handlebars (222.4459.16)
com.github.syuchan1005.npmscriptrunner (1.0)
ink.organics.pojo2json (1.2.6)
com.chuntung.plugin.mybatisbuilder (1.2.4)
com.suiyiwen.plugin.idea.apidoc (3.0.5)
MavenRunHelper (4.26.0-IJ2022.2)
cn.wuzhizhan.plugin.mybatis (2020.12.18)
com.thoughtworks.gauge (222.4459.16)
com.alibabacloud.intellij.toolkit-intellij (2023.6.1-222)
site.forgus.plugins.api-generator-plus (1.0.14)
ru.adelf.idea.dotenv (2022.2)
com.bruce.intellijplugin.generatesetter (2.8.3)
com.itangcent.idea.plugin.easy-yapi (2.6.3.212.0)
com.dengzii.plugin.converter (1.0)
com.intellij.bigdatatools (222.3345.33)
com.sunq.action.WebStormPX2REMTools (2.1.5)
com.dubreuia (2.3.0)
com.baomidou.plugin.idea.mybatisx (1.5.5)
Kotlin: 222-1.7.10-release-334-IJ4554.10
IntelliJ IDEA 2023.2 (Ultimate Edition)
Build #IU-232.8660.185, built on July 26, 2023
Licensed to signup scooter
You have a perpetual fallback license for this version.
Subscription is active until August 1, 2025.
Runtime version: 17.0.7+7-b1000.6 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 4092M
Cores: 4
Registry:
editor.minimap.enabled=true
Non-Bundled Plugins:
net.vektah.codeglance2 (1.5.5)
com.github.redfoos.logstash-intellij-plugin (0.8.3)
com.robohorse.robopojogenerator (2.4.1)
com.github.holgerbrandl.pasteimages/ (1.2.4)
com.starxg.mybatis-log-plugin-free (1.3.0)
de.netnexus.camelcaseplugin (3.0.12)
com.sunq.action.WebStormPX2REMTools (2.1.5)
com.intellij.ideolog (222.1.0.0)
dev.meanmail.plugin.nginx-intellij-plugin (2022.1.1)
CMD Support (1.0.5)
Key Promoter X (2023.2.0)
AceJump (3.8.8)
mobi.hsz.idea.gitignore (4.5.2)
ink.organics.pojo2json (1.2.6)
GsonFormatPlus (1.6.1)
GenerateSerialVersionUID (3.0.3)
String Manipulation (9.7.1)
org.jetbrains.plugins.hocon (2023.1.0)
com.chuntung.plugin.mybatisbuilder (1.2.4)
Dart (232.8660.129)
com.thoughtworks.gauge (232.8660.142)
com.alibabacloud.intellij.toolkit-intellij (2023.8.1-232)
org.jetbrains.idea.grammar (2021.1.2)
com.ccnode.codegenerator.mybatis.generator (2018.12.14)
com.ctfin.idea.mybatis-generator (1.1.1)
com.suiyiwen.plugin.idea.apidoc (3.0.5)
com.github.syuchan1005.npmscriptrunner (1.0)
com.dengzii.plugin.converter (1.0)
com.bruce.intellijplugin.generatesetter (2.8.3)
com.itangcent.idea.plugin.easy-yapi (2.5.9.212.0)
com.dmarcotte.handlebars (232.8660.88)
org.arxing.chinese_converter (1.0.1)
cn.wuzhizhan.plugin.mybatis (2020.12.18)
CopyRestUrl (1.5)
MavenRunHelper (4.23.222.2964.0)
Pythonid (232.8660.185)
ru.adelf.idea.dotenv (2024.1)
com.intellij.bigdatatools.core (232.8660.206)
com.intellij.bigdatatools.kafka (232.8660.206)
com.intellij.bigdatatools.binary.files (232.8660.206)
com.intellij.bigdatatools.rfs (232.8660.206)
com.intellij.bigdatatools.metastore.core (232.8660.206)
com.intellij.bigdatatools.flink (232.8660.206)
com.intellij.bigdatatools.spark (232.8660.206)
com.intellij.bigdatatools.zeppelin (232.8660.206)
com.intellij.bigdatatools (232.8660.206)
com.baomidou.plugin.idea.mybatisx (1.6.3)
Kotlin: 232-1.9.0-IJ8660.185