IDEA: Adding default serial version ID for Serializable howto? - serialization

Using IntelliJ, whenever I add implements Serializable it does not offer to add a default serial version id, similar to how Eclipse does it.
Using Eclipse, if i do the same, i get a warning and an offer to
How can i get the same behaviour in IntelliJ please?

This inspection is disabled by default, you need to enable it in Settings:
Once enabled, the quick fix becomes available on Alt+Enter while standing on the highlighted class name:

Related

IntelliJ autocomplete partially working

I've just added some Java classes to my project in IntelliJ IDEA 2017.2.3. When I attempt to use autocomplete to add the elsewhere in the project, it does not find them. It shows older classes, but not the new classes. If I type out the class name, IntelliJ asks to import it and everything works.
What am I missing? Why would if find some of my classes and not others?
Not the end of the world, but it is very annoying.
Well, I just discovered the invalidate cache option. This appears to have fixed the issue, by forcing a re-index.
For anyone else facing this problem, the option is under File -> Invalidate Caches / Restart...

#NotNull, #Nonnull etc. all don't work in IntelliJ IDEA

I have tried annotating a field with
org.checkerframework.checker.nullness.qual.NonNull
org.jetbrains.annotations.NotNull
javax.annotation.Nonnull
And in all cases, assigning a null to it generates no complaints from IntelliJ 2016.2.
public class GreetingController {
#NotNull Integer x = 3;
public void foo() { x = null; }
}
That all compiles fine according to IntelliJ.
This page from IntelliJ specifically states that "IntelliJ IDEA highlights the problems “on-the-fly”, so you can see the inspection results right in the editor." I have even copied the example code (public class TestNullable) into my editor and it produces no errors.
This other page from IntelliJ states you can change the annotations it responds to. So I chose javax.annotation.Nonnull and made sure that was the one I was using in my code, still no luck.
To be clear, what I'm hoping for, and what I understand should be provided, is that the editor window / compiler alerts me to the problem (I am not looking for a runtime check, NullPointerException already works fine at runtime.)
In case it didn't work in real time, I tried "Rebuild Project".
I'm sure this must work, what am I doing wrong?
I have uploaded an example of this not working here: ZIP download.
As I can see from your screenshots and the sample project, IntelliJ IDEA does show you the warnings. Note that these warnings are shown by the code inspections which are running on the fly and will be displayed in the editor or in the Analyze | Inspect Code results. These warnings will not be displayed by the compiler.
Note that you can configure the warnings highlighting if needed (for example add the underwave effect):
You can also change the severity of the inspection (like to Error):
You may also want to vote for this feature request:
IDEA-78625 Provide inspection severity level that will work like validation and abort compilation
As a bonus, pay attention to the javax.annotation.Nullable annotation, it may be not what you think it's for, see this comment and the documentation. For some years IntelliJ IDEA has incorrectly suggested to use this annotation, while the correct one for such cases would be javax.annotation.CheckForNull:
This annotation is useful mostly for overriding a Nonnull annotation.
Static analysis tools should generally treat the annotated items as
though they had no annotation, unless they are configured to minimize
false negatives. Use CheckForNull to indicate that the element value
should always be checked for a null value.
"Settings" > "Inspections" > "Probable Bugs" > "Constant conditions & exceptions"
Tick the first option: "Suggest #NotNull annotation for methods that possibly return null and report nullable values passed to non-annotated parameters.
Click "Configure Annotations". By default, Intellij will use their own annotations from org.jetbrains.annotation. I was using the more general (my own opinion) annotations from javax.annotation.
I set Nullable to: javax.annotation.Nullable
I set NotNUll to : javax.annotation.NotNull
In order to set these new options, you must click them, then click the tiny checkmark button to the right to set it. Selecting the javax.annotation annotations then hitting "OK" will NOT lock in the new settings, you must use the checkbox button.
After successfully specifying javax.annotation.Nullable and javax.annotation.NotNull, the code correctly highlighted null problems.
The best that this can do is offer up warnings. It will not stop compilation from happening, since the annotations do not prohibit or preclude code compilation from taking place.
Be sure that you have the appropriate inspections enabled in your IDE, and be sure that you remain aware of what parameters you're passing into your method. The IDE can at best warn you, but it can't really stop you.
Alternatively, introduce a unit test to fail if that method receives a null parameter, and rely on that to ensure that you're not breaking code or expectations.

IntelliJ IDEA FXML is not correctly recognized

Why does IntelliJ does not recognize all tags in this *.fxml document?
The JavaFX plugin is enabled and some of the tags are recognized... (I created this with SceneBuilder)
How to solve this problem?
Don't rely on the wildcard import for resolution of the fx:root type attribute.
Use:
<fx:root type="javafx.scene.layout.GridPane" ...
Instead of:
<fx:root type="GridPane" ...
Then all of the node type specific tags (such as <children>) will resolve OK in the Idea editor and not be highlighted in red.
Do not ask me why this is so as I do not know.
I tested the above on Idea 15 EAP ideaIU-143.116.4-custom-jdk-bundled.dmg, it may or may not work on earlier Idea editions.

Intellij idea deprecated no strikeout/strikethrough

I'm using IntelliJ IDEA v12. When I import a project, there’s a strikeout/strikethrough line on the method which has the annotation #Deprecated, but I used alt+enter to disable it. So, how can I reactivate this feature? I want to display that strikethrough, thanks!
Open Settings -> Type Inspections to go to inspection settings -> Type Deprecated to find out all deprecated related inspection settings -> Check Deprecated API usage.
IntelliJ had a bug in 2018.3, 2018.2.2 (182.4129.33). It was fixed in builds 191.65, 183.3691.
Setting -Dide.text.effect.new.metrics=false in the .vmoptions fixes the problem.
In addition to Ionghua's answer .....
If you find that IntelliJ is still not striking out deprecated methods, even though you have enabled the inspection as above, check to make sure that your code is not ignoring deprecation warnings with #SuppressWarnings("deprecation").
In addition to longhua's answer... and vegemite4me...
Another possible source for this problem might be custom color themes.
If you are using a custom theme, make sure that it contains strikethrough. I was using monokai-sublime and there is no strikethrough for #Deprecated annotations. When I changed the color theme from monokai to darcula strikethrough worked as expected.
I found that the only thing that worked for me with version 2019.2 192.5728.98, runtime 11.0.3+12-b304.10 was to use Help | Edit VM Options and add -Dide.text.effect.new.metrics=false

JetBrains Idea: exclude package & classes from autocomplete

How can I exclude some classes from autocomplete, but not from project?
I'm trying to develop on flash with starling library. The problem is that IDE always suggest me a built-in classes, which I probably don't want to use, even if I import another class.
http://monosnap.com/image/7VRQpIhqIPRK2wgBKp41GOU9i
I'm tried to exclude in a Settings -> Editor -> Auto Import, but it takes no effect on a autocomplete.
May be I can reorder autocomplete suggest, for placing the libraries classes on top?
I'm using idea 12.0.4
Does Settings -> Editor -> Auto Import -> Exclude from Import and Completion help you?
Now in Preferences | Editor | General | Auto Import
There are instructions at https://www.jetbrains.com/help/idea/auto-completing-code.html for disabling, but they didn't work for me until invalidating caches and restarting.
Pull up autocomplete, highlight the offending item, then option-return and exclude it, either at the class or method level. Then invalidate caches and restart.