= null ? bar : bar.trim();
+ }
+}
\ No newline at end of file
diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/ConditionalCanBeOptionalInspectionTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/ConditionalCanBeOptionalInspectionTest.java
new file mode 100644
index 000000000000..5c64f875d084
--- /dev/null
+++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/ConditionalCanBeOptionalInspectionTest.java
@@ -0,0 +1,27 @@
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.java.codeInspection;
+
+import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
+import com.intellij.codeInspection.ConditionalCanBeOptionalInspection;
+import com.intellij.codeInspection.LocalInspectionTool;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Tagir Valeev
+ */
+public class ConditionalCanBeOptionalInspectionTest extends LightQuickFixParameterizedTestCase {
+ @NotNull
+ @Override
+ protected LocalInspectionTool[] configureLocalInspectionTools() {
+ return new LocalInspectionTool[]{new ConditionalCanBeOptionalInspection()};
+ }
+
+ public void test() {
+ doAllTests();
+ }
+
+ @Override
+ protected String getBasePath() {
+ return "/inspection/conditionalCanBeOptional/";
+ }
+}
diff --git a/resources-en/src/inspectionDescriptions/ConditionalCanBeOptional.html b/resources-en/src/inspectionDescriptions/ConditionalCanBeOptional.html
new file mode 100644
index 000000000000..a2fccd9d1dc1
--- /dev/null
+++ b/resources-en/src/inspectionDescriptions/ConditionalCanBeOptional.html
@@ -0,0 +1,16 @@
+
+
+Suggests to replace a null-check condition with an Optional chain. E.g.
+return str == null ? "" : str.trim();
+Could be rewritten as
+return Optional.ofNullable(str).map(String::trim).orElse("");
+While the replacement is not always shorter, this could be a helpful step for further refactoring
+ (e.g. changing the method return value to an Optional).
+Note that when not-null branch of the condition returns null, the corresponding mapping step will produce an empty Optional
+possibly changing the semantics. If it cannot be statically proven that semantics will be preserved, quick-fix action name
+will contain "(may change semantics)" notice and inspection highlighting will be turned off.
+
+This inspection only reports if the project or module is configured to use a language level of 8 or higher.
+New in 2018.1
+
+
\ No newline at end of file