今天遇到一个问题,jd-gui-0.3.5 反编译jar包出现如下问题:
// ERROR //
public void checkAndLogin() { // Byte code:
// 0: iconst_0
// 1: istore_1
// 2: iload_1
// 3: ifne +208 -> 211
// 6: ldc2_w 15
// 9: invokestatic 17 java/lang/Thread:sleep (J)V
// 12: aload_0
// 13: getfield 18 com/erayt/fx/price/service/impl/FxPriceOperateServiceImpl:requestPriceDao Lcom/erayt/quotation/dao/RequestPriceDao;
// 16: ldc 19
// 18: invokeinterface 20 2 0
// 23: astore_2
// 24: getstatic 9 com/erayt/fx/price/service/impl/FxPriceOperateServiceImpl:LOGGER Lcom/erayt/solar/logging/Log;
// 27: ldc 21
// 29: iconst_2
// 30: anewarray 11 java/lang/Object
// 33: dup
// 34: iconst_0
// 35: aload_2
// 36: aastore
// 37: dup
// 38: iconst_1
// 39: aload_0
// 40: getfield 22 com/erayt/fx/price/service/impl/FxPriceOperateServiceImpl:appName Ljava/lang/String;
// 43: aastore
// 44: invokevirtual 12 com/erayt/solar/logging/Log:info (Ljava/lang/String;[Ljava/lang/Object;)V
// 47: aload_0
// 48: getfield 23 com/erayt/fx/price/service/impl/FxPriceOperateServiceImpl:uniqueName Ljava/lang/String;
// 51: aload_2
// 52: ldc 24
// 54: invokevirtual 25 java/lang/String:split (Ljava/lang/String;)[Ljava/lang/String;
// 57: iconst_0
// 58: aaload
// 59: invokevirtual 26 java/lang/String:equals (Ljava/lang/Object;)Z
// 62: ifeq +7 -> 69
// 65: aload_0
// 66: invokevirtual 27 com/erayt/fx/price/service/impl/FxPriceOperateServiceImpl:login ()V
// 69: ldc2_w 28
// 72: invokestatic 17 java/lang/Thread:sleep (J)V
// 75: goto +136 -> 211
// 78: astore_3
// 79: getstatic 9 com/erayt/fx/price/service/impl/FxPriceOperateServiceImpl:LOGGER Lcom/erayt/solar/logging/Log;
// 82: ldc 31
// 84: iconst_2
// 85: anewarray 11 java/lang/Object
// 88: dup
// 89: iconst_0
// 90: aload_3
// 91: invokevirtual 32 java/lang/InterruptedException:getMessage ()Ljava/lang/String;
// 94: aastore
// 95: dup
// 96: iconst_1
// 97: aload_3
// 98: aastore
// 99: invokevirtual 33 com/erayt/solar/logging/Log:error (Ljava/lang/String;[Ljava/lang/Object;)V
// 102: goto +109 -> 211
// 105: astore_2
// 106: getstatic 9 com/erayt/fx/price/service/impl/FxPriceOperateServiceImpl:LOGGER Lcom/erayt/solar/logging/Log;
// 109: ldc 35
// 111: iconst_2
// 112: anewarray 11 java/lang/Object
// 115: dup
// 116: iconst_0
// 117: aload_2
// 118: aastore
// 119: dup
// 120: iconst_1
// 121: aload_2
// 122: invokevirtual 36 java/lang/Exception:getMessage ()Ljava/lang/String;
// 125: aastore
// 126: invokevirtual 33 com/erayt/solar/logging/Log:error (Ljava/lang/String;[Ljava/lang/Object;)V
// 129: iconst_0
// 130: istore_1
// 131: ldc2_w 28
// 134: invokestatic 17 java/lang/Thread:sleep (J)V
// 137: goto +71 -> 208
// 140: astore_2
// 141: getstatic 9 com/erayt/fx/price/service/impl/FxPriceOperateServiceImpl:LOGGER Lcom/erayt/solar/logging/Log;
// 144: ldc 31
// 146: iconst_2
// 147: anewarray 11 java/lang/Object
// 150: dup
// 151: iconst_0
// 152: aload_2
// 153: invokevirtual 32 java/lang/InterruptedException:getMessage ()Ljava/lang/String;
// 156: aastore
// 157: dup
// 158: iconst_1
// 159: aload_2
// 160: aastore
// 161: invokevirtual 33 com/erayt/solar/logging/Log:error (Ljava/lang/String;[Ljava/lang/Object;)V
// 164: goto +44 -> 208
// 167: astore 4
// 169: ldc2_w 28
// 172: invokestatic 17 java/lang/Thread:sleep (J)V
// 175: goto +30 -> 205
// 178: astore 5
// 180: getstatic 9 com/erayt/fx/price/service/impl/FxPriceOperateServiceImpl:LOGGER Lcom/erayt/solar/logging/Log;
// 183: ldc 31
// 185: iconst_2
// 186: anewarray 11 java/lang/Object
// 189: dup
// 190: iconst_0
// 191: aload 5
// 193: invokevirtual 32 java/lang/InterruptedException:getMessage ()Ljava/lang/String;
// 196: aastore
// 197: dup
// 198: iconst_1
// 199: aload 5
// 201: aastore
// 202: invokevirtual 33 com/erayt/solar/logging/Log:error (Ljava/lang/String;[Ljava/lang/Object;)V
// 205: aload 4
// 207: athrow
// 208: goto -206 -> 2
// 211: return
//
// Exception table:
// from to target type
// 69 75 78 java/lang/InterruptedException
// 6 69 105 java/lang/Exception
// 131 137 140 java/lang/InterruptedException
// 6 69 167 finally
// 105 131 167 finally
// 167 169 167 finally
// 169 175 178 java/lang/InterruptedException }
代码如下:
@Override
public void checkAndLogin(){
boolean runOk=false;
while(!runOk){
try {
Thread.sleep(2000);
String value=requestPriceDao.getMarginPriceLockByName(Constant.LOCK_NAME_PRICELOCK);
LOGGER.info("持有锁value【{}】,本机【{}】", value,appName);
if(uniqueName.equals(value.split(MarginConstants.SEMICOLON_SPLITER)[0])){
login();
}
break;
} catch (Exception e) {
LOGGER.error("数据库报错等待20s后重新加锁【{}】【{}】",e,e.getMessage());
runOk=false;
}finally{
try {
Thread.sleep(1000*20);
} catch (InterruptedException e) {
LOGGER.error("[ERR]线程等待错误:[{}]", e.getMessage(),e);
}
}
}
}
代码本身没有看出问题,有需要优化的地方,但是怎么看都不会有编译出错的地方,在排查这个问题的时候,方向一直是查为什么会反编译不出来。
后来网上看到一个帖子,说反编译工具的问题,换一个工具试试。
然后去下载了另外一个工具:https://github.com/deathmarine/Luyten
下载步骤:
-
- 1、git clone https://github.com/deathmarine/Luyten.git 下载
- 2、cd Luyten
- 3、mvn clean install (jdk8)
- 4、到 target 目录下, java -jar luyten-0.5.3.jar
然后反编译看了一下,正常编译,但是和代码有一些区别
@Override
public void checkAndLogin() {
boolean runOk = false;
while (!runOk) {
try {
Thread.sleep(2000L);
final String value = this.requestPriceDao.getMarginPriceLockByName("PRICE_LOCK");
FxPriceOperateServiceImpl.LOGGER.info("\u62a5\u4ef7\u5f15\u64ce\u8fde\u63a5\u6210\u529f\u540e\uff0c\u6301\u6709\u9501value\u3010{}\u3011,\u672c\u673a\u3010{}\u3011", new Object[] { value, this.appName });
if (this.uniqueName.equals(value.split(";")[0])) {
this.login();
}
}
---这里少了 break; 不是我删除的,真的是没有。
catch (Exception e) {
FxPriceOperateServiceImpl.LOGGER.error("\u6570\u636e\u5e93\u62a5\u9519\u7b49\u5f8520s\u540e\u91cd\u65b0\u52a0\u9501\u3010{}\u3011\u3010{}\u3011", new Object[] { e, e.getMessage() });
runOk = false;
try {
Thread.sleep(20000L);
}
catch (InterruptedException e2) {
FxPriceOperateServiceImpl.LOGGER.error("[ERR]\u7ebf\u7a0b\u7b49\u5f85\u9519\u8bef:[{}]", new Object[] { e2.getMessage(), e2 });
}
}
finally {
try {
Thread.sleep(20000L);
}
catch (InterruptedException e3) {
FxPriceOperateServiceImpl.LOGGER.error("[ERR]\u7ebf\u7a0b\u7b49\u5f85\u9519\u8bef:[{}]", new Object[] { e3.getMessage(), e3 });
}
}
}
}
具体分析,break 并不合适,修改标志位最合适。 break 修改成 runOk=true; 反编译一切正常。
总结:
反编译报错,可能是工具问题,但是不能忽略他,要找到问题的原因。