jsr-305 | Automatically exported from code.google.com/p/jsr-305
kandi X-RAY | jsr-305 Summary
kandi X-RAY | jsr-305 Summary
Automatically exported from code.google.com/p/jsr-305
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Prints a number
- Check number
jsr-305 Key Features
jsr-305 Examples and Code Snippets
Community Discussions
Trending Discussions on jsr-305
QUESTION
I've been using IntelliJ IDEA as a Java IDE for a decade, and I created my favorite syntax highlight scheme back in 2009. It remains unmodified since around 2015 just because I find it very comfortable to me making reading code easier and faster. However, there are some syntax elements that are not easy to read under certain circumstances. The most important elements among those, I guess, are Java annotations that appear messy and are just hard to read if there are too many annotations. I prefer the following annotations order scheme:
- (possibly disabled) "entry points":
@Disabled
,@Test
,@RequestMapping
,@Scheduled
, etc; - Java core:
@Override
,@FunctionalInterface
,@Target
,@RetentionPolicy
, etc; - contracts: JSR-305 (
@Nonnull
,@Immutable
), Checker Framework; - codegen: Lombok
@Getter
,@EqualsAndHashCode
, etc; - runtime: various custom @Foo's and @Bar's,
@Entity
,@OneToMany
,@JsonProperty
etc; - documentation: @Api***, etc;
@SuppressWarnings
as the least significant one.
Sometimes I place them in wrong order and it makes reading code less convenient making me feel that the code style is not as strict as I want it to be. My question is: it possible to define an order for annotations (or their groups) so I could reorder? IntelliJ IDEA can do exactly the same for imports.
(Also, is it possible to highlight such groups with different colors?)
...ANSWER
Answered 2019-Oct-25 at 13:40There is a feature request to support such behaviour, please upvote: https://youtrack.jetbrains.com/issue/IDEABKL-7684
QUESTION
When I add Hystrix support to a kotlin spring boot project, some fields of an abstract class are suddenly null. It seems the Hystrix proxy does not handle fields properly:
I have an abstract kotlin class ClientHandler
having two fields logger
and test
directly initialized. I have a kotlin subclass SomeHandler
of ClientHandler
which I use via autowiring in a class. As expected when using the subclass the two fields are initialized.
But when I add Hystrix support (uncomment @EnableHystrix
and @HystrixCommand
) the two fields logger
and test
in the abstract class are suddenly null.
Do you have any ideas why this happens? Spring adds a proxy class to the SomeHandler
class, Hystrix does the same. So I assume something goes wrong in the double proxying in combination with Kotlin!? I did the same with a java class and everything went fine.
ANSWER
Answered 2019-Apr-03 at 10:23I was able to figure it out by myself: The function send
has to be open, so Hystrix and Spring will create a proper Proxy around the abstract class including the two fields.
QUESTION
I'm using Kotlin with https://github.com/vojtechhabarta/typescript-generator to generate TypeScript definitions for my classes that are used in an API.
To preserve nullability information, typescript-generator can use annotations present on fields and methods. It supports arbitrary annotation class names, listed in the build script.
Kotlin, for some reason, annotates nullable fields with @org.jetbrains.annotations.Nullable
rather than the JSR-305 annotation, @javax.annotation.Nullable
.
While the JSR-305 annotation has RetentionPolicy.RUNTIME
, the Jetbrains annotation has RetentionPolicy.CLASS
, making it unsuitable for introspection by libraries which use Java Reflection to detect annotations.
Is it possible to have Kotlin generate standards-based annotations instead of the JetBrains proprietary annotations?
If not, I'm interested in simple solutions to handle the issue. Perhaps a Gradle plugin that can generate JSR-305 annotations from the JetBrains ones or similar. I would really prefer to not have to double-annotate everything with a ?
and @Nullable
.
ANSWER
Answered 2017-Sep-16 at 09:49Kotlin is designed to emit its own (JetBrains) annotations. This choise was made because JSR 305 was never released and there is no legal way for JetBrains to bundle JSR 305 annotations with compiler, since the license on (a dormant) JSR 305 does not allow it. The legal status of the com.google.code.findbugs:jsr305
maven artifact is likewise murky, since javax
package namespace is specifically reserved for JSRs.
There are the following possible solutions:
Write a custom Gradle plugin that post-processes Kotlin-compiled class files and changes
org.jetbrains.annotations.*
annotations to the correspondingjavax.annotation.*
annotations (NotNull
toNonnull
andNullable
toNullable
) and changes the corresponding attiributes from runtime-invisible annotations to runtime-visible ones.Patch
typescript-generator
so that it used Kotlin reflection APIs in addition to Java Reflection to get nullablitity information from Kotlin classes. The entry point is for this task is kotlin extension of JavaClass
instance that allows to retrieve all the Kotlin metadata.Add
jackson-module-kotlin
totypescript-generator
. This module is using Kotlin's reflection to get all the Kotlin specific information and feed it to Jackson, whiletypescript-generator
is using Jackson bean introspection to get its type information, so it might just work.
QUESTION
Building bazel-0.5.0rc9 failed for BadExitStatusException: Process exited with status 50
. Terminal output error as follow
ANSWER
Answered 2017-Jun-06 at 11:12I get upwards error, because i add some print info at CrosstoolConfigurationLoader.java
file for debug. Removing it can fix it.
QUESTION
How can an OSGi bundle become active without Bundle-Activator in the MANIFEST-MF file? For example, Google guava can run as a bundle and become active in Karaf container but the MANIFEST-MF file doesn't include Bundle-Activator property.
...ANSWER
Answered 2017-Mar-08 at 20:36For one, there are also other means of starting a logic in a bundle, for example it could be Blueprint, or Declarative Services. But I doubt guava does have that, so what you see here is a typical case. An OSGi bundle usually follows the following steps:
a) installed
b) resolved
c) starting
d) active
e) stopping
f) uninstalled
This is for all bundles, only fragments will stay in the resolved state as a fragment bundle itself can't be started/activated.
If your bundle (or guava in this case) doesn't have an explicit Activator class which will be called in the active stage, the bundle still can be active.
QUESTION
I am generating Java source files for my project using a source generation tool (antlr). However, I am writing most, if not all of my code, in Kotlin.
Kotlin already offers great Java interop, so using the generated sources is not a problem. However, because of how Kotlin brings Java's nullable types into a null-safe system, I lose most of the null-safety that I use Kotlin for. At the very best I have warnings of platform types (make type explicit to avoid subtle bugs); at the worst I have unexpected crashes and subtle bugs.
Kotlin does, however, respect nullability annotations, such as JSR-305, FindBugs, Lombok, Eclipse, and JetBrains's respective forms of @Nullable
/@NonNull
, bringing those in as the appropriate non-null type or optional.
Because the code is generated and I have access to the source (and understand how it works), I know which functions can/not return null
, and want to annotate them as such so they include neatly into my null-safe code. However, I cannot add annotations directly into the code, as it is generated during the build step and would overwrite any manual changes.
Is it possible to / what is the best way to annotate the nullability of generated java sources for the purpose of use in null-safe code?
...ANSWER
Answered 2017-Jan-10 at 05:07The best way would be to modify the source code generator so that it includes the annotations that you require.
If you can't modify the generator (e.g. because the generator is proprietary and you don't have its source code) then you can do this using bytecode engineering. For example, this page on the ASM site gives one way to do it:
Of course, in either case you need some way to tell the tool (the generator, the bytecode rewriter, whatever) which methods should be annotated.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install jsr-305
You can use jsr-305 like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the jsr-305 component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page