Executing some Java Code in a Jenkins Plugin, I get the following:
Caused by: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;II)V
at de.dwpbank.build.jenkins.plugins.templateutility.auxconfig.ConfigHarvester.extract(ConfigHarvester.java:123)
And I'm wondering how to fully understand the NoSuchMethodError message:
checkArgument(ZLjava/lang/String;II)V
What I get is, I called the checkArgument method with at least a String as a parameter, the L is the size of the pointer (Long - isn't it?) but what does the Z, the II after the semicolon and the V stand for?
Here's the call off checkArgument:
int maxBoundary = configDescriptorTree.getMaxBoundary();
int size = auxArray.length;
Preconditions.checkArgument(maxBoundary >= size,
"AuxInstance Array size '%s' > maxBoundary '%s'", size,
maxBoundary);
So this call would match to the following signature of checkArgument:
public static void checkArgument(boolean b, @Nullable String errorMessageTemplate, int p1, int p2)
Through autoboxing it could also match this one:
checkArgument(boolean b, @Nullable String errorMessageTemplate, @Nullable Object p1, @Nullable Object p2)
Or this one:
public static void checkArgument(boolean expression, @Nullable String errorMessageTemplate, @Nullable Object... errorMessageArgs)
Could this ambiguity the reason for the NoSuchMethodError?
I'm wondering that I can execute the call from the Jenkins script console withouth any problem:
com.google.common.base.Preconditions.checkArgument(1 >= 2,
"AuxInstance Array size '%s' > maxBoundary '%s'", 2,
1);
Result
java.lang.IllegalArgumentException: AuxInstance Array size '2' > maxBoundary '1'
Typically this kind of error messages have to do with library dependencies linking to wrong versions.
The library of de.dwpbank.build.jenkins.plugins.templateutility.auxconfig.ConfigHarvester
is probably linked to a version of Google Guava which is not available in your Jenkins installation.
If you want to know more which jar files are involved you can run this code to locate the jar files:
public static void findJarForClass(Class clazz) {
CodeSource src = clazz.getProtectionDomain().getCodeSource();
if (src != null) {
java.net.URL jar = src.getLocation();
System.out.printf("%s ----> %s%n", clazz, jar);
}
}
This static call will point you to the jar files of the involved classes.
If you know the versions you can inspect the jar file of de.dwpbank.build.jenkins.plugins.templateutility.auxconfig.ConfigHarvester
, especially in their META-INF/maven folder and see what the pom.xml file says about its dependencies. Typically this file will point you to the expected libraries - in your case to the expected Guava library version.