蚂蚁构建期间在具体类上获取抽象类错误

时间:2018-10-18 07:28:25

标签: java build ant

我正在尝试构建项目,但出现以下错误。 我检查了从中导入AsyncMessage的jar,该类是具体的而不是抽象的。

flex.messaging.messages.AsyncMessage is abstract; cannot be instantiated
[javac]                             AsyncMessage msg = new AsyncMessage();
[javac]                                                ^

下面是我在被引用的flex jar中找到的完整AsyncMessage类。

    package flex.messaging.messages;

import flex.messaging.log.Log;
import flex.messaging.util.UUIDUtils;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

public class AsyncMessage
  extends AbstractMessage
  implements SmallMessage
{
  private static final long serialVersionUID = -3549535089417916783L;
  public static final String SUBTOPIC_HEADER_NAME = "DSSubtopic";
  private static byte CORRELATION_ID_FLAG = 1;
  private static byte CORRELATION_ID_BYTES_FLAG = 2;
  protected String correlationId;
  protected byte[] correlationIdBytes;

  public String getCorrelationId()
  {
    return this.correlationId;
  }

  public void setCorrelationId(String correlationId)
  {
    this.correlationId = correlationId;
  }

  public Message getSmallMessage()
  {
    if (getClass() == AsyncMessage.class) {
      return new AsyncMessageExt(this);
    }
    return null;
  }

  public void readExternal(ObjectInput input)
    throws IOException, ClassNotFoundException
  {
    super.readExternal(input);

    short[] flagsArray = readFlags(input);
    for (int i = 0; i < flagsArray.length; i++)
    {
      short flags = flagsArray[i];
      short reservedPosition = 0;
      if (i == 0)
      {
        if ((flags & CORRELATION_ID_FLAG) != 0) {
          this.correlationId = ((String)input.readObject());
        }
        if ((flags & CORRELATION_ID_BYTES_FLAG) != 0)
        {
          this.correlationIdBytes = ((byte[])input.readObject());
          this.correlationId = UUIDUtils.fromByteArray(this.correlationIdBytes);
        }
        reservedPosition = 2;
      }
      if (flags >> reservedPosition != 0) {
        for (short j = reservedPosition; j < 6; j = (short)(j + 1)) {
          if ((flags >> j & 0x1) != 0) {
            input.readObject();
          }
        }
      }
    }
  }

  public void writeExternal(ObjectOutput output)
    throws IOException
  {
    super.writeExternal(output);
    if (this.correlationIdBytes == null) {
      this.correlationIdBytes = UUIDUtils.toByteArray(this.correlationId);
    }
    short flags = 0;
    if ((this.correlationId != null) && (this.correlationIdBytes == null)) {
      flags = (short)(flags | CORRELATION_ID_FLAG);
    }
    if (this.correlationIdBytes != null) {
      flags = (short)(flags | CORRELATION_ID_BYTES_FLAG);
    }
    output.writeByte(flags);
    if ((this.correlationId != null) && (this.correlationIdBytes == null)) {
      output.writeObject(this.correlationId);
    }
    if (this.correlationIdBytes != null) {
      output.writeObject(this.correlationIdBytes);
    }
  }

  protected String toStringFields(int indentLevel)
  {
    String sep = getFieldSeparator(indentLevel);
    String s = sep + "clientId = " + (Log.isExcludedProperty("clientId") ? "** [Value Suppressed] **" : this.clientId);
    s = s + sep + "correlationId = " + (Log.isExcludedProperty("correlationId") ? "** [Value Suppressed] **" : this.correlationId);
    s = s + sep + "destination = " + (Log.isExcludedProperty("destination") ? "** [Value Suppressed] **" : this.destination);
    s = s + sep + "messageId = " + (Log.isExcludedProperty("messageId") ? "** [Value Suppressed] **" : this.messageId);
    s = s + sep + "timestamp = " + (Log.isExcludedProperty("timestamp") ? "** [Value Suppressed] **" : String.valueOf(this.timestamp));
    s = s + sep + "timeToLive = " + (Log.isExcludedProperty("timeToLive") ? "** [Value Suppressed] **" : String.valueOf(this.timeToLive));
    s = s + sep + "body = " + (Log.isExcludedProperty("body") ? "** [Value Suppressed] **" : bodyToString(this.body, indentLevel));
    s = s + super.toStringFields(indentLevel);
    return s;
  }
}

仍然不确定为什么Java编译器会引发此错误。 我在构建时使用Java 1.6版和Ant版本1.7。 请检查我是否有任何遗漏。 谢谢

1 个答案:

答案 0 :(得分:2)

很显然,您向我们展示的课程不是正在编译的课程。

所以我认为问题在于上面的源代码与public class OfferServiceTest { @Mock private OfferRepository offerRepositoryMock; private OfferServiceImpl offerServiceImpl = new OfferServiceImpl(); //Or use autowired maybe, I am not veru much familiar with Spring @Test public void getAllOffersTest() { List<Offer> offerList=new ArrayList<>(); offerList.add(new Offer("SE",new Date(), 10)); when(offerRepositoryMock.findAll()).thenReturn(offerList); assertNotNull(offerServiceImpl.getAllOffers()); assertEquals(offerList, offerServiceImpl.getAllOffers()); } 试图对其进行编译的已编译类不匹配。

怎么办?

  • 也许您在javac类上有多个版本 类路径。 (也许两个JAR文件包含相同的类?)

  • 也许您已经更改了AsyncMessage类的源代码 但没有重新编译。

  • 也许您已经下载了不同版本的源代码到 编译后的代码的版本。

通常来说,这种问题表示某种形式的版本或版本混合。