Phpinspectionsea: FP: "[EA] Null pointer exception may occur here."

Created on 11 May 2020  路  6Comments  路  Source: kalessil/phpinspectionsea

| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Plugin | Php Inspections (EA Ultimate), 3.0.9.1 |
| Language level | PHP 7.2 |

Current behaviour

<?php

class HtmlFilter { public function foo() { return 'bar'; } }

class HtmlTable {

    /**
     * @var null|HtmlFilter
     */
    public $HtmlFilter = null;

    /**
     * @return HtmlFilter
     */
    public function getFilter() {
        if ($this->HtmlFilter === null) {
            throw new Exception('no "HtmlFilter" used for: ' . static::class);
        }

        return $this->HtmlFilter;
    }

    public function foo()
    {
        return $this->getFilter()->foo();
    }
}

Expected behaviour

do not show the Null pointer exception because getFilter() only return HtmlFilter

Environment details

PhpStorm 2020.1.1
Build #PS-201.7223.96, built on April 30, 2020
Licensed to Portable UTF-8 / Lars Moelleken
Subscription is active until February 27, 2021
For non-commercial open source development only.
Runtime version: 11.0.6+8-b765.40 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.4.0-177-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 5120M
Cores: 4
Registry: run.processes.with.pty=TRUE, ide.tooltip.initialDelay=885, ide.balloon.shadow.size=0
Non-Bundled Plugins: com.dubreuia, uk.co.ben-gibson.remote.repository.mapper, Key Promoter X, String Manipulation, com.alayouni.ansiHighlight, com.andrey4623.rainbowcsv, com.intellij.ideolog, com.upsolver.PreCommitHook, dev.arunvelsriram.desccron, mobi.hsz.idea.gitignore, name.kropp.intellij.makefile, net.seesharpsoft.intellij.plugins.csv, net.vektah.codeglance, izhangzhihao.rainbow.brackets, ru.adelf.idea.dotenv, NEON support, lv.midiana.misc.phpstorm-plugins.deep-keys, de.espend.idea.php.toolbox, de.espend.idea.php.annotation, fr.adrienbrault.idea.symfony2plugin, com.kalessil.phpStorm.phpInspectionsUltimate, me.artspb.idea.eval.plugin, net.king2500.plugins.PhpAdvancedAutoComplete, de.espend.idea.php.generics
Current Desktop: Unity

Most helpful comment

It started a few releases ago. I'm pretty sure Jetbrains changed their type inference system and they sometimes ignore the phpdoc type declared and read directly the type in the returned variable.

Adding a return type in signature solved the issue for us, but not on vendors.

All 6 comments

Same FP with Doctrine. Sad...

grafik
grafik

Environment details

PhpStorm 2020.1.1
Build #PS-201.7223.96, built on April 30, 2020
Licensed to United Promotion GmbH / Aleskei Sitnikov
Subscription is active until November 18, 2020
Runtime version: 11.0.6+8-b765.40 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.9.0-12-amd64
GC: ParNew, ConcurrentMarkSweep
Memory: 981M
Cores: 2
Registry: run.processes.with.pty=TRUE, debugger.valueTooltipAutoShowOnSelection=true, ide.tooltip.initialDelay=801
Non-Bundled Plugins: mobi.hsz.idea.gitignore, de.espend.idea.localization, com.kalessil.phpStorm.phpInspectionsEA, de.espend.idea.php.annotation, fr.adrienbrault.idea.symfony2plugin, ua.in.dej.myEmmet
Current Desktop: MATE

It started a few releases ago. I'm pretty sure Jetbrains changed their type inference system and they sometimes ignore the phpdoc type declared and read directly the type in the returned variable.

Adding a return type in signature solved the issue for us, but not on vendors.

@orklah thanks for the hint 馃憤

@orklah should we probably create an issue on https://youtrack.jetbrains.com/issues?q=project:%20PhpStorm ?

Same here, I am using a ?? operator to check the value returned from another function and it is ignoring it.

@orklah should we probably create an issue on https://youtrack.jetbrains.com/issues?q=project:%20PhpStorm ?

Possibly. I didn't care enough to create it at the time and I don't have a real case on hand right now.
Feel free to create it though!

Was this page helpful?
0 / 5 - 0 ratings