I am running a project on IntelliJ that has a mix of kotlin and Java; when I build the project I get a heap of errors which shouldnt occur. for example, the following code throws the error:
Error:(129, 23) Kotlin: Unresolved reference: +=
override fun startMessagingService(RPCOps: RPCOps?) {
// Start up the embedded MQ server
messageBroker?.apply {
runOnStop += Runnable { messageBroker?.stop() }
start()
bridgeToNetworkMapService(networkMapService)
}
}
Obviously these are just basic operations and shouldn't fail. When I click on the error message it doesn't show an error in the actual code file. Perhaps my configuration is wrong? If so; how to go about fixing it?
There are many other errors that throw on basic operations like the one above.
Related
I'm using the Groovy Spreadsheet Builder within one of my Grails projects to export some data as Excel file.
Everything works great until I create a runnable jar (using gradle assemble) and use this.
I'm using the builder within a service like this:
class ExcelService {
...
void export(OutputStream outputStream) {
...
PoiSpreadsheetBuilder.create(outputStream).build {
apply ExcelStylesheet
...
}
}
...
}
When I try to export my data from the app started using the generated jar I will get the following MissingMethodException:
groovy.lang.MissingMethodException: No signature of method: my.package.ExcelService.apply() is applicable for argument types: (java.lang.Class)
The (Java) interface of SpreadsheetBuilder looks like this:
public interface SpreadsheetBuilder {
void build(#DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = WorkbookDefinition.class) #ClosureParams(value = FromString.class, options = "builders.dsl.spreadsheet.builder.api.WorkbookDefinition") Configurer<WorkbookDefinition> workbookDefinition);
}
While debugging the execution of the code and the jar I found the difference while stepping through invokeMethod() of ClosureMetaClass.
When closure.getResolveStrategy(); in the working version is called Closure.DELEGATE_FIRST will be returned. Debugging the jar, the result will be 0 so that the MissingMethodException will be thrown later due to the wrong resolve strategy.
For now I have no idea how to solve this problem.
What is/could be the reason for this behavior?
What can I do to solve this issue?
I'm using Grails 3.3.8 with Java OpenJDK 1.8.0_192.
If you don't need to support JDK 7, you could upgrade to Groovy Spreadsheet Builder 2.0.0.RC1 which is only JDK 8 compatible but appears to solve the problem.
#ClosureParams and #DelegatesTo are applicable to parameters of type groovy.lang.Closure. In this case, you have applied it to Configurer<WorkbookDefinition>.
Here is the code that's expected to produce error:
public class App {
public static void main (String[] args) {
tick();
}
public static void tick () {
System.out.print("hi");
Note that the closing angled bracket of both, the method tick() and class App is missing. Although the IDE indicates this error while writing code, this compiles and runs just fine. It doesn't look like an issue with Java (or my OS) as doing javac in the command line surely does fail.
What's even funnier...the following code throws a Runtime exception after successfully executing tick():
public class App {
public static void main (String[] args) {
tick();
public static void tick () {
System.out.print("hello..");
Here I skipped closing bracket of main too.
I have installed the development version of Netbeans that has support for Java 9.
[This is a comment more than an answer, but I wanted to include screen shots to show that I cannot reproduce either issue.]
An interesting problem. I just downloaded the most recent nightly build (NetBeans Dev 201803060002) and built your code using Oracle JDK 9.04.
Neither of your code examples would compile for me. For the first example the error for the final line was "reached end of file while parsing System.out.print("hi");". Here is a screen shot:
For the second example, where you removed the closing bracker of main() the additional error reported was "illegal start of expression public static void tick () {":
I suggest that you try the following:
Create a new project and new class "App2" to see if you can replicate the issue with that same version of NetBeans.
If you cannot then review why App compiles and App2 does not.
If you can replicate the problem then download the most recently nightly build to see if you can still replicate the problem (i.e. Invalid source code compiles cleanly). If you cannot then I don't think it is worth raising a bug report or spending further time on the matter.
However, if you can replicate the problem then by all means raise a bug report. But I strongly recommend being able to replicate the failure before doing that. Otherwise you are likely to get a WORKSFORME response if the NetBeans team cannot replicate the issue.
One more thing: it would be helpful to update your OP with the stack trace for that RuntimeException, which you should also include in your bug report.
Ah...I see it now. At some point of time I checked the "Always run without asking" checkbox and since then my IDE is ignoring all the compile time errors without any warnings.
Sorry guys...my bad.
My code is giving an error below;
Exception in thread "main" java.lang.NoSuchMethodError:
com/myApp/Client.cypherCBC(Ljava/lang/String;)Ljava/lang/String;
But it's working fine in an another local environment. My code so far is below;
try {
System.out.println("Encrypted CBC passwd : "
+ Client.cypherCBC("CypherThePassword"));
} catch (Exception e) {
e.printStackTrace();
}
This is due to a run-time JAR or class mismatch. the "Client" class which was there at the time you compile your application has a static method "cypherCBC" which gets String parameter, but at run-time class loader has loaded the "Client" class which doesn't have that kind of method (same name with same signature).
if you can debug the application at runtime, put a break-point at the line which exception was thrown, then try to evaluate following expression,
Client.class.getResource("Client.class")
, then you can find where the class has been leaded from, then you can decompile and try to troubleshoot the issue.
I got the same error while running a web application in Weblogic.
The reason for this error is there are two versions of classes are in the environment.To fix this you have to figure out which .class is using at the run time.
I used following to identify which class is loaded at run time.
-verbose:class
There is a duplicate class on your classpath.
So, That is why JVM is getting confused that which one needs to pick because both classes have a same method with a different signature that you are trying to call.
I think everybody who has to work with Maven and Java8 knows of this bug that release builds suddenly fail for spelling mistakes in JavaDoc. As a company we decided to let some poor sap (aka me) work all of them out. Now I'm stuck with the following "error":
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.10.1:javadoc (default-cli) on project org.acme.project.demo: An error has occurred in JavaDocs report generation:
[ERROR] Exit code: 1 - C:\jenkins\workspace\Project 2.0\org.acme.project.demo\src\main\java\org\acme\project\demo\SomeClass.java:36: error: cannot access OtherClass
[ERROR] import org.acme.project.OtherClass;
[ERROR] ^
[ERROR] bad class file: C:\jenkins\workspace\Project 2.0\org.acme.project\target\org.acme.project-2.0.0-SNAPSHOT-v20150128-1503.jar(org/acme/project/OtherClass.class)
[ERROR] undeclared type variable: N
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath.
I tried to clean it up a bit, but to summarize: Project B throws the exception when it tries to resolve a method call to Project A (yes, while generating JavaDoc!). The method in question looks like that:
public static <N extends Bean> void hookContinousImageFunction(final OtherClass<N> dialog,
final ImageGroup imageGroup, N model, final BiFunction<Image, N, ? extends Image> imageFunction) {
final Image original = imageGroup.getImage();
dialog.setOnCancelClick((notUsed) -> imageGroup.setImage(original));
model.addPropertyChangeListener(new ContinousImageFunctionListener<>(dialog, imageGroup, imageFunction));
dialog.setInitialModel(model);
}
It doesn't even have JavaDoc (not that any of this should matter when the generation of Project A's JavaDoc is already finished, and Maven is trying to generate JavaDoc for Project B).
As of now, we have this bug in multiple projects, about 1 out of 5. Project A (the one with a typed method / class like above) is more often than not in an entirely different build reactor and sometimes completely out of our control.
How do I fix this bug inside a bug?
(As a as a side note, the error occurs on the Jenkin's running with Java 1.8.0_31 and jdk1.8.0_40 or locally with 1.8.0_45, 1.8.0_60, but not locally with 1.8.0_20, but JavaDoc generation hasn't been that reliable, so I can't say for sure it has something to do with the Java version.)
I got the same kind of error message using a central build while having no problems in my local build. (Unfortunately I have no details about the central build environment.)
Adding a '#param ' explanation in the JavaDoc comment for the static method in question solved the issue. Adapted to the given example I did something like this:
/**
* #param <N> This is the class that ...
*/
public static <N extends Bean> void hookContinuousImageFunction(...)
Okay the answer is to a) downgrade Java to 1.8.0_20, or - if that is not possible - b) to use this code in the pom.xml to disable JavaDoc of the project until the Java people feel the need to fix the bug:
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
</properties>
While Compiling an Scala 2.10 Project, I got an error I cannot even understand
java.lang.NoClassDefFoundError: no Java class corresponding to MongoPersistable.this.type found
at scala.reflect.runtime.JavaMirrors$JavaMirror.typeToJavaClass(JavaMirrors.scala:1218) ~[scala-reflect-2.10.0.jar:na]
at scala.reflect.runtime.JavaMirrors$JavaMirror.runtimeClass(JavaMirrors.scala:202) ~[scala-reflect-2.10.0.jar:na]
at scala.reflect.runtime.JavaMirrors$JavaMirror.runtimeClass(JavaMirrors.scala:65) ~[scala-reflect-2.10.0.jar:na]
...
How is this even possible to get such a error message if the code got well in eclipse in first place?
Following line of Code produces this error:
trait MongoPersistable {
def save() {
val dao : MongoDAO[MongoPersistable.this.type] = MongoDAO[this.type];
....
I would upload more code if I know where to search