8

I want to compile simple code with oracle jdk 1.8:

class Foo { public static void test(@NotNull String a) {} } 

But idea not understand such code, and suggest to add:

import com.sun.istack.internal.NotNull; 

after that compilation inside idea works, but if run build by gradle with such build.gradle:

version '1.0-snaphshot_03.03.2017' apply plugin: 'java' targetCompatibility = '1.8' sourceCompatibility = '1.8' repositories { mavenCentral() } task sourcesJar(type: Jar, dependsOn: classes) { classifier = 'sources' from sourceSets.main.allSource } dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' } artifacts { archives sourcesJar } 

I got error:

error: package com.sun.istack.internal does not exist import com.sun.istack.internal.NotNull; error: cannot find symbol public static void test(@NotNull String a) { ^ symbol: class NotNull location: class Foo 

I thought that NotNull was added in 1.8? How can I make possible of usage of NotNull in idea and gradle?

3
  • Please check stackoverflow.com/questions/4963300/…. I think it is @NonNull. Commented Mar 3, 2017 at 10:48
  • Do you mean javax.annotation.Nonnull? Commented Mar 3, 2017 at 10:48
  • Try Optional<T> instead. Commented Mar 3, 2017 at 10:58

2 Answers 2

8

There is no @NotNull annotation in the standard JDK that would be meant for general use (the com.sun.internal.istack.NotNull is definitely not for your usage, as it's an internal class).

The Java Bean validation framework (JSR-303) has javax.validation.constraints.NotNull, which is implemented by (for example) Hibernate validator. That's probably what you're looking for.

Sign up to request clarification or add additional context in comments.

Comments

2

I think you should be adding org.jetbrains.annotations.NotNull as this is Used by IntelliJ IDEA IDE for static analysis. Refer :
IntelliJ Documentation
This SO Question

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.