What does EOF FOUND '}' mean in Check style? - java

I'm using intellij communicated version and also add checkstyle plugin
how ever, i made simple java file just say hello
public class hello {
public static void main(string[] final args)
{
system.out.println("hello, world");
}
}
it's simply run. however checkstyle tell me there is problem at the last line.
he told me
Got an exception-expecting EOF, Found '}' error
I don't know what is the problem. block is correctly close.
is there something i need to add or fix that ?

This problem became a real issue in the checkstyle project. Basically it was related with the use of lambdas, yet the problem exposed herebefore is clarely not related to Java 8 lambdas. You can check the issue here. You can solve it by specifying a valid version. In gradle it would be:
apply plugin: 'checkstyle'
checkstyle {
toolVersion = "6.1.1"
}

Try formatting it like
public class Hello
{
public static void main(String[] args)
{
System.out.println("hello, world");
}
}
and the "s" in system.out.println and string[], should be capital
Checkstyle is a tool which is used to find flaws in formatting and coding conventions followed if any exists in the code. The rules are set using by configuring the checkstyle. And if any part of your code does not abide by them, it will throw an exception. In most of the cases exceptions will be self explanatory. You can use google depending on the exception you get.

Related

Complete Current Statement behaves differently in Scala in IntelliJ

I recently upgraded my IDEA and now using IntelliJ IDEA 2022.2 Ultimate Edition.
I found the Complete Current Statement in Scala code behaves differently as in Java code, which is very annoying.
For example in Java code:
public static void main(String[] args) {
String foo = "bar"
}
Press Complete Current Statement shortcut(shift+cmd+enter for me) anywhere in line #2, will add a ; at the end of the line, and an auto-indent will be applied too:
public static void main(String[] args) {
String foo = "bar";
}
Then press Complete Current Statement again will bring you to a new line when there is nothing more to adjust.
public static void main(String[] args) {
String foo = "bar";
}
In previous version of IntelliJ, I roughly remember the behavior is same for Scala code.
But in this version of IntelliJ, when I try to do samething in Scala code, for example:
def foo (): Unit = {
throw new RuntimeException
}
When I press Complete Current Statement in line #2, nothing happens.
Could anyone please help me checkout why or how should I config to align with Java code's behavior? Thank you very much!
You don't need to use that in Scala because semicolons are optional, and almost never used. Actually, your Scala code sample is already what you would call a "complete statement".
For formatting what I do and recommend is having set File -> Settings -> Tools -> Actions on save and check Reformat code and optionally Optimize imports, and it will do both whenever you save your source file using Ctrl + S. I believe it's Cmd + S on your Mac.
This uses the default Intellij Formatter for Scala. Scala also has it's own Formatter called Scalafmt with customizable setups more control of formatting different Scala features based on your preferences. This is located at Settings -> Editor -> Code Style -> Scala.
If for some reason you would still like to use your shortcut key, then the only thing the Complete current statement can do to your Scala code is auto-indenting the current line, which for some reason it doesn't so it seems to be a bug on Intellij's side. But what you can do is replace the Auto-Indent Lines shortcut key to use your Complete current statement shortcut key instead and get the same behavior.

can't step into java source code. "step into" somehow act like "step over"

I'm trying to studying how a method in java String class works, so I created some customised code that calls that String class method.
As you can see, I have set a break point in my own code and I have set another break point in the java String class source code.
While I'm in debug mode and is on line 7 of my code, I pressed step into.
However, rather than stepping into the String class method indexOf, eclipse instead moved onto line 8 of my code.
Why is this happening? how can I step into the java string method source code?
public class TestingIndexOfMethod {
public static void main(String[] args) {
final String stringToBeSearchedThrough = "hello world";
final String substringToLookFor = "ll";
int a = stringToBeSearchedThrough.indexOf(substringToLookFor, 0);
System.out.println(a);
}
}
Edit 1:
I have already check to see, if "use step filter" is activated before asking this question on SO, and it is not activated. So I dont think "use step filter" is the problem here.
Edit 2:
step into works fine with methods I defined myself
Most probably there is a step filter which instructs the debugger to skip certain classes.
In the preferences dialog (menu Window -> Preferences) check the step filtering settings.
Either deactivate Use Step Fitlers which deactivates all step filters or deactivate the filter for the classes java.* only.
edit Another reason might be that your project is using a JRE instead of a JDK for the execution. Find below an example using a Java 8 JRE respective a Java 8 JDK.
project build path using a JRE (pay attention to jre1.8.0_112)
project build path using a JDK (pay attention to JavaSE-1.8)
edit 2 To determine the used Java runtime library add following statement in your code and run it in debug mode.
...
public static void main(String[] args) {
Stream.of(System.getProperty("sun.boot.class.path")
.split(File.pathSeparator))
.filter(s -> s.endsWith("rt.jar"))
.forEach(System.out::println);
...

How to capture the parameters of System.out.println() in AspectJ's aspect and display in pointcut?

I am very new to AspectJ...just started to learn.
Till now i am able to get the parameters of user defined method in my aspect and print the captured parameter in my pointcut.
Curiously i started to think to print the contents of System.out.println() in my pointcut's advice and written the following simple code:
HelloClass.java:
public class HelloClass
{
public static void main(String a[])
{
System.out.println("hello sachin");
}
}
HelloAspect.java:
public aspect HelloAspect
{
pointcut callPointcut(String message ) :call(void java.lang.System.out.println(String))&& args(message);
before( String message) : callPointcut(message )
{
System.out.println("Fetced in point cut:"+message);
//System.out.println("In the advice attached to the call pointcut");
}
}
Then i compiled both the files using ajc HelloClass.java HelloAspect.java
It compiled successfully with one worning as follows:
and when i run program using java HelloClass
it Outputs as: Hello sachin where it should be as Fetced in point cut:Hello sachin.
So can anyone point out where i am going wrong or missing something . .Thank you in advance . .
I was shocked still .. 2 days after posting,no one answered my this question... but its fine i have found a solution and realized where i was wrong. it was the mistake in my signature of println method().
This is the correct signature of println:
void around(String str) :
call(void java.io.PrintStream.println(String)) && args(str)
and it worked fine for me . .
catch of method calls from JRE is not so easy.
is easier to learn aspectj when you try to catch your own methods.
Define your own println method perhaps in HelloClass and try again.
for work with aspectj and jre classes you need to recompile jre classes with aspectj compiler.
http://dev.eclipse.org/mhonarc/lists/aspectj-users/msg09350.html

JIRA - Jira post function -- How to update "fix version" field?

My scenario is: One step in my jira workflow should have the ability to unschedule a task i.e. set a Fix Version to "None".
I noticed that I was not able to update fix version in a workflow post function - I don't know exactly why, but anyway I did implement a jira plugin to help me solve my problem but I know I'm going against jira structure (even java good coding practices :)). I am not sure if my implementation can cause problems, but indeed it is working in my jira instance 4.1.x.
How I've implemented a plugin to update fix version in a post function, 2 very similar ways:
public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
// Here I create an empty Collection to be the new value of FixVersion (empty because I need no version in Fix Version)
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
MutableIssue issue = this.getIssue(transientVars);
Collection<Version> newFixVersion = new ArrayList<Version>();
issue.setFixVersions(newFixVersion);
issue.store();
}
}
public class BrandsclubPostFunctionUnschedule extends AbstractJiraFunctionProvider {
// here I clear the Collection I got from "old" Fix Version and I have to set it again to make it work.
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
MutableIssue issue = this.getIssue(transientVars);
Collection fixVersions = issue.getFixVersions();
fixVersions.clear();
issue.setFixVersions(fixVersions);
issue.store();
}
}
I presume that a real solution should use classes like: ChangeItemBean, ModifiedValue, IssueChangeHolder - taking as example the updateValue methods from CustomFieldImpl (from jira source code, project: jira, package: com.atlassian.jira.issue.fields).
My point of publishing this here is:
Does anyone know how to implement a jira plugin containing a post function to change Fix Version correctly?
If you want to do it properly take a look in the code for
./jira/src/java/com/atlassian/jira/workflow/function/issue/UpdateIssueFieldFunction.java processField()
Postfunctions that take input parameters are not documented yet it seems. Other places to go for code are other open source plugins.
Atlassian has a tutorial on doing just about exactly what you want to do, here:
I do it like in this snippet:
List<GenericValue> genericValueList = issueManager.getIssues(issues);
versionManager.moveIssuesToNewVersion(genericValueList, lastVersion, newVersion);

How do I setup Eclipse to stop on the line an exception occurred?

How can I setup Eclipse to stop at the point an exception occurred.
I have an Eclipse breakpoint setup to break on an exception. In the code example below, the problem I'm having is Eclipse tries to open the Integer source code. Is there any way to just have debugger break at the point shown in my code example? If I move down the stack trace, I will get to this line, it'd be nice if there's a way to do this without the "Source not found" window coming up.
This can be done in Visual Studio, so it's driving me crazy not being able to find a way to do this in Eclipse.
package com.test;
public class QuickTest
{
public static void main(String[] args)
{
try
{
test();
}
catch(NumberFormatException e)
{
System.out.println(e.getMessage());
}
}
private static void test()
{
String str = "notAnumber";
Integer.parseInt(str);//<----I want debugger to stop here
}
}
I'm not sure how else to get there, but I just do:
Window -> Show View -> Breakpoints
And in that tab there is a "J!" that lets you set breakpoints on exceptions.
Preferences -> Java -> Debug -> Step Filtering
Choose packages you want to filter out when debugging (java.*, sun.*, etc)
On debug make sure the little step filtering arrow is selected.
This should do the trick.
Can't you just set a breakpoint on the Integer.parseInt(str) line?
If you point your Eclipse project at using a JDK instead of a JRE it should pick up the source code for all of the platform classes (Integer etc).
The Debug view will show the entire stack of the current execution. You need to select the line you want to see. It will be same as you had a breakpoint there, you can see all the variables etc.

Categories