AspectJ: VerifyError - java

I'm experimenting with Aspect-Oriented Programming. I've installed the AspectJ-Plugin in Eclipse and followed all the steps mentioned in this tutorial.
All connections between the created aspects work, but when I try to run the project, I receive the following exception:
HelloException in thread "main" java.lang.VerifyError: Expecting a stackmap frame at branch target 6 in method helloworld.World.<clinit>()V at offset 0
at helloworld.Hello.sayHello(Hello.java:11)
at helloworld.Hello.main(Hello.java:6)
When I empty the class World.aj and run the project, everything works and I receive the expected "Hello" in the console.
Here are the classes I created during the tutorial:
Hello.java
package helloworld;
public class Hello {
public static void main(String[] args) {
sayHello();
}
public static void sayHello() {
System.out.print("Hello");
}
}
World.aj
package helloworld;
public aspect World {
pointcut greeting() : execution(* Hello.sayHello(..));
after() returning() : greeting() {
System.out.println(" World!");
}
}

the problem doesn't seem related to AOP.
I think this is the same eclipse bug described here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=362591
Ayushman Jain 2011-11-02 02:47:32 said:
If you're stuck, please use the VM argument -XX:-UseSplitVerifier to run the
program. I confirm that there is no verify error with this option.
May you can also try to download the latest version of eclipse.

I don't have the points to comment on #KC answer, which worked for me,
so leaving this as an additional answer
-XX:-UseSplitVerifier
did work for me
I have an AspectJ project that was running fine in eclipse 3.7
then all of a sudden started getting that error
adding the -XX:-UseSplitVerifier to the launcher configuration solved it.

I also followed the tutorial, and encountered the same error. And here is how I solved it.
I found out that that the execution environment JRE selected by default with my eclipse, JavaSE-1.7, had an issue with AspectJ. So what you have to do, is change the execution environment JRE, choose for example JavaSE-1.6.
After, you can follow the tutorial, and obtain the desired output! :)
Hope this helps!

Related

Java Records and Lombok annotation - IntelliJ

Just trying a hands-on the java.lang.Record. I have gone through the documentation and the JEP-359 for some understanding. So upon reading about the implicit declaration of the constructor I thought of mixing it up with an existing code generation library - Lombok!
Now what I've ended up creating as a minimal reproducible example is this record
import lombok.AllArgsConstructor;
#AllArgsConstructor
public record Java(String version) {
}
which when compiled using IntelliJ successfully produces the class file which looks like
public final class Java extends java.lang.Record {
private final java.lang.String version;
public Java(java.lang.String version) { /* compiled code */ }
... rest of the compiled code
}
Note that the constructor for the .class file is just what I would have expected in the two worlds independently as well. But, further trying to create an instance of this record fails during compilation in IntelliJ :
public class MixOfWorlds {
public static void main(String[] args) {
System.out.println(new Java("14").version()); // cannot resolve constructor
}
}
I would create a further simpler example to perform the compilation with javac and execution with java tools. I am still looking for an answer if this is a possible expected behavior that could occur because of something I might have overlooked?
IntelliJ IDEA 2020.1 EAP (Community Edition)
Build #IC-201.6487.11, built on March 18, 2020
Runtime version: 11.0.6+8-b765.15 x86_64
macOS 10.14.6
This is how it reflects in IntelliJ for both the cases - with and without the #AllArgsConstructor.
Following up on this and with some help online from the IntelliJ developers, I had tried the following steps to resolve this --
I was assured that it looks more about javac-lombok interaction and was not connected to IDE.
I could actually gain the confidence to try running the code despite the highlighted error(which looks like a compile-time error) and it successfully executed to print "14" as expected.
I can confirm that after disabling the "Lombok Plugin" installed in the IDE, the highlighted error disappears.
Note: The second step was with the plugin installed. So in short, it just happens that the plugin gets to highlight the code as if it wouldn't compile, but the actual execution is handled by IntelliJ properly. (Kudos!)
Edit: With the 1.8.20 release, Lombok prevents a record to be annotated with an AllArgsConstructor any more. You can access the official changelog here.

GLPK for Java lib seems not be found

I am trying to use GLPK for my java project. I followed the link here https://wiki.nps.edu/pages/viewpage.action?pageId=113606659 to install and config the GLPK for java. And in the java project, I used
compile 'org.gnu.glpk:glpk-java:1.12.0'
to include the glpk java project. However, when I try to create the test class in my project , then it gives the following error.
public class ILPTest {
#SuppressWarnings({ "rawtypes", "unchecked"})
public static void main(String[] args) {
testGLPK();
}
private static void testGLPK() {
System.out.println(GLPK.glp_version());
}
}
The GLPK in the statement GLPK.glp_version() can not be resolved.
UPDATE: One thing I noticed is in the link I posted above, I have an error when I try the step 11 sudo make install as below
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
So when I try to run sudo ldconfig (from another url http://glpk-java.sourceforge.net/gettingStarted.html), I got a command not found error. Can anyone help here? Thanks in advance.
It turns out that I need to manually add the lib glpk-java-1.12.0.jar into the project.

Visual Studio Code: Java does not execute unless package statement is commented out

When opening any Java project, or maven project, new or old, Java throws "Error: Could not find or load main class App" at runtime. Java will only run if "package foo;" is commented out i.e. "//package foo;".
I am using the code runner extension, which works with every other language. It runs as expected in java if the package statement is excluded or commented out.
This is able to be replicated in every new java program created or opened inside VS Code, even projects created in IntelliJ (Which run as expected) and opened in VS Code.
Environment:
Operating System: Mac OSX Mojave 10.14.4
JDK version: 1.8.0_202
Visual Studio Code version: 1.33.0
Java extension version: 0.6.0
I could never get my java code to run inside VS Code, until I removed the package statement (commented it out). Once the package statement is removed my code runs as expected, but has a 'problem' inside VS Code saying "The declared package "" does not match the expected package "app"Java(536871240)"
//package app;
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello Java");
}
}
Example1
Example2
Make sure you've already setup the JDK environment in the right way
Try to clean your workspace:Clean the workspace directory
Make sure to reload a new workspace after you finished all the above steps.
I fixed by using the above steps when I have this error. Hope it can also works on your side.

IntelliJ Idea Completion Error

I am new to Idea IDE. After installed it for a few days, I was fascinated with its outstanding features.
However, while I was actually writing code yesterday. I discovered that when the auto completion popped out, it showed nothing about the method of the object , merely some basic template say sync() var() ..... etc.
I have tried to setup the environment (Check the power save ...etc), but those previous solution seems to be for those whose auto-completion is turned off . Is there a way to fix it ?
THANKS IN ADVANCE!!
When you have create your project, you might not have marked it as a Java project and provide a SDK.
You can check it in File -> Project Settings -> Project -> Project SDK.
If not, you can download the JDK on the Oracle site http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
You can also try to write a
public static void main(String... args) {
System.out.println("It works !");
}
and write click on the "main" word. You should have a "Run 'Main'" option.

Error in Eclipse -Could not find the main class(Running NFC Example)

I am trying to run an example which I pulled out from open-nfc.org.
I have followed all the instructions provided by this site, however when I am trying to run the program I am getting the following error
Error: Could not find or load main class Processing
I have attached the program
package NFC;
import org.opennfc.*;
public class FinalNFC {
public static void main(String[] args) {
NfcManager mgt = NfcManager.getInstance(null);
System.out.println(mgt.getProperty("open_nfc.version"));
try {
System.out.println(mgt.getProperty("nfcc.firmware_version"));
} finally {
try {
mgt.stop();
} catch(NfcException e) {
System.out.println("Error :" + e.getMessage());
}
}
}
}
I have tried searching for this problem in stack overflow but nothing is seemed to solve this issue !
I am new to the Eclipse, so step by step Solution is really appreciated.
Else can anyone give me some site so that i can code in nfc using java ?
Firstly, Try running your program through native command line process, though your program syntactically seems ok but still that will give an idea about APIs as i could guess you're naive for eclipse.
Secondly, i had faced similar problem before what worked for me was re-configuring JVM.
Thirdly, What kind of project you have made in eclipse. For example if you are running Dynamic Web Project i.e. if you're running complete project itself then error you are getting is obvious. Then try running only the file by right clicking on it and select run file.
Hope this helps.
Firstly right click on your eclipse project and select "run as - Java Application". Then it will start searching main class and it will show you lots of classes then in search window type "FinalNFC" then select that class and run it.

Categories

Resources