# java:S3655 Call "Optional#isPresent()" before accessing the value

**URL:** <https://community.sonarsource.com/t/java-s3655-call-optional-ispresent-before-accessing-the-value/25526>\
**Category:** SonarQube Cloud\
**Created:** [May 29, 2020, 11:08pm UTC](https://community.sonarsource.com/t/java-s3655-call-optional-ispresent-before-accessing-the-value/25526 "2020-05-29T23:08:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![agabrys](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/agabrys/32/2744_2.png) [@agabrys](https://community.sonarsource.com/u/agabrys)\
**Post date:** [May 30, 2020, 3:37pm UTC](https://community.sonarsource.com/t/java-s3655-call-optional-ispresent-before-accessing-the-value/25526/2 "2020-05-30T15:37:23Z")

</div>

This is not a false positive. Your code is as follow:

```auto
if (obj.getOptional().isPresent()) {
    obj.getOptional().get() // issue
}

```

There is no guarantee that the first `getOptional()` method execution returns the same object as the second `getOptional()` method execution. You have to store the value locally:

```auto
Optional<String> value = obj.getOptional()
if (value.isPresent()) {
    value.get() // no issue
}

```

---

_[View the full topic](https://community.sonarsource.com/t/java-s3655-call-optional-ispresent-before-accessing-the-value/25526)._
