program tip

java.lang.NoSuchMethodError 메시지 해석

radiobox 2020. 11. 15. 11:07
반응형

java.lang.NoSuchMethodError 메시지 해석


다음과 같은 런타임 오류 메시지가 나타납니다 (스택 추적의 첫 번째 줄과 함께 줄 94를 가리키는). 나는 왜 그런 방법이 없다고 말하는지 알아 내려고 노력하고 있습니다.

java.lang.NoSuchMethodError: 
com.sun.tools.doclets.formats.html.SubWriterHolderWriter.printDocLinkForMenu(
    ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;
    Ljava/lang/String;Z)Ljava/lang/String;
at com.sun.tools.doclets.formats.html.AbstractExecutableMemberWriter.writeSummaryLink(
    AbstractExecutableMemberWriter.java:94)

writeSummaryLink의 94 행은 다음과 같습니다.

질문
"ILcom"또는 "Z"는 무엇을 의미합니까?
괄호 안에 4 가지 유형 (ILcom / sun / javadoc / ClassDoc; Lcom / sun / javadoc / MemberDoc; Ljava / lang / String; Z)이 있고 괄호 뒤에 하나가있는 이유 Ljava / lang / String; printDocLinkForMenu 메소드에 분명히 5 개의 매개 변수가있을 때?

코드 세부
사항 writeSummaryLink 메소드는 다음과 같습니다.

protected void writeSummaryLink(int context, ClassDoc cd, ProgramElementDoc member) {
    ExecutableMemberDoc emd = (ExecutableMemberDoc)member;
    String name = emd.name();
    writer.strong();
    writer.printDocLinkForMenu(context, cd, (MemberDoc) emd, name, false);  // 94
    writer.strongEnd();
    writer.displayLength = name.length();
    writeParameters(emd, false);
}

다음은 94 행이 호출하는 메소드입니다.

public void printDocLinkForMenu(int context, ClassDoc classDoc, MemberDoc doc,
        String label, boolean strong) {
    String docLink = getDocLink(context, classDoc, doc, label, strong);
    print(deleteParameterAnchors(docLink));
}

에서 4.3.2 JVM을 사양의 :

문자 유형 해석
------------------------------------------
B 바이트 부호있는 바이트
C char 유니 코드 문자
D 배정 밀도 부동 소수점 값
F float 단 정밀도 부동 소수점 값
정수 정수
J long long 정수
L <클래스 이름>; 클래스의 인스턴스 참조
S 짧은 부호있는 짧은
Z 부울 참 또는 거짓
[하나의 배열 차원 참조

에서 섹션 4.3.3 방법은 디스크립터 :

메서드 설명자는 메서드가 사용하는 매개 변수와 반환되는 값을 나타냅니다.

MethodDescriptor:
        ( ParameterDescriptor* ) ReturnDescriptor

그러므로,

(ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z) Ljava/lang/String;

번역 :

A method with int, ClassDoc, MemberDoc, String and boolean as parameters, and which returns a String. Note that only reference parameters are separated with a semicolon, since the semicolon is part of their character representation.


So, to sum up:

Why there are four types in parentheses (ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z) and one after the parentheses Ljava/lang/String; when the method printDocLinkForMenu clearly has five parameters?

There are five parameters (int, ClassDoc, MemberDoc, String, boolean) and one return type (String).


What does "ILcom" or "Z" mean?

Those are mapping types for native types. You can find an overview here.

Native Type    | Java Language Type | Description      | Type signature
---------------+--------------------+------------------+----------------
unsigned char  | jboolean           | unsigned 8 bits  | Z
signed char    | jbyte              | signed 8 bits    | B
unsigned short | jchar              | unsigned 16 bits | C
short          | jshort             | signed 16 bits   | S
long           | jint               | signed 32 bits   | I
long long      | jlong              | signed 64 bits   | J
__int64        |                    |                  |
float          | jfloat             | 32 bits          | F
double         | jdouble            | 64 bits          | D

In addition, the signature "L fully-qualified-class ;" would mean the class uniquely specified by that name; e.g., the signature "Ljava/lang/String;" refers to the class java.lang.String. Also, prefixing [ to the signature makes the array of that type; for example, [I means the int array type.


As to your next question:

Why there are four types in parentheses (ILcom/sun/javadoc/ClassDoc;Lcom/sun/javadoc/MemberDoc;Ljava/lang/String;Z) and one after the parentheses Ljava/lang/String; when the method printDocLinkForMenu clearly has five parameters?

Because you're not running the code you think you're running. The actually running code is trying to call exactly that method described in the error message, with actually five parameters (the I should be counted separately) and a Stringreturn type, but this method doesn't exist in the runtime classpath (while it was available in the compiletime classpath), hence this error. Also see the NoSuchMethodError javadoc:

Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.

Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

So, verify if you're actually running the right version of the code as you've posted in your question and are using the right dependencies in the runtime classpath and not having duplicate different versioned libraries in the classpath.

Update: the exception signifies that the actual code is (implicitly) trying to use the method like as follows:

String s = printDocLinkForMenu(context, cd, (MemberDoc) emd, name, false);

Because it is expecting a String outcome while it is declared void.

참고URL : https://stackoverflow.com/questions/2945862/interpreting-java-lang-nosuchmethoderror-message

반응형