今天遇到一個問題,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; 反編譯一切正常。
總結:
反編譯報錯,可能是工具問題,但是不能忽略他,要找到問題的原因。