Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP code template insertion fails and empties the line #7170

Closed
EtienneDelepine opened this issue Mar 18, 2024 · 10 comments · Fixed by #7425
Closed

PHP code template insertion fails and empties the line #7170

EtienneDelepine opened this issue Mar 18, 2024 · 10 comments · Fixed by #7425
Assignees
Labels
kind:bug Bug report or fix PHP [ci] enable extra PHP tests (php/php.editor)
Milestone

Comments

@EtienneDelepine
Copy link

EtienneDelepine commented Mar 18, 2024

Apache NetBeans version

Apache NetBeans 21

What happened

In a PHP file, I type "for" or "iter", the autocompletion pop-up opens, I choose the "iter" shortcut to insert the code for (index=0;$i<count($array);$i++){} but instead of inserting this code, the line is emptied.

The error message is :
A java.lang.NullPointerException has occurred.
Cannot invoke "String.hashCode() because "< local4 >" is null
messages.log

Maybe it is linked to the deactivation of one of the plugins (the only plugin in "Base IDE" category that is inactivated is "Embedded Browser UI - JavaFX WebView").

Language / Project Type / NetBeans Component

PHP

How to reproduce

see "what happened"

Did this work correctly in an earlier version?

No / Don't know

Operating System

win 11

JDK

java version "18.0.2.1" 2022-08-18 Java(TM) SE Runtime Environment (build 18.0.2.1+1-1) Java HotSpot(TM) 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing)

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

No

@EtienneDelepine EtienneDelepine added kind:bug Bug report or fix needs:triage Requires attention from one of the committers labels Mar 18, 2024
@neilcsmith-net
Copy link
Member

Please check the messages log file - it seems to be a binary file rather than text??

@neilcsmith-net neilcsmith-net added the pending-response Awaiting further information to be supplied label Mar 18, 2024
@EtienneDelepine
Copy link
Author

EtienneDelepine commented Mar 18, 2024

The file is text but in fact the first line had NULL characters, I removed them

@neilcsmith-net neilcsmith-net added PHP [ci] enable extra PHP tests (php/php.editor) and removed pending-response Awaiting further information to be supplied labels Mar 18, 2024
@junichi11
Copy link
Member

@EtienneDelepine
Could you write your exact steps?
I can't reproduce it.

  1. Create a new file
  2. Type for & CC
  3. Select for template
<?php

for // CC & select for template here

@EtienneDelepine
Copy link
Author

It's strange because it is not happening in all files.
I tested in a project I'm working on. In a new PHP file it works, as well as some PHP class methods. But in others, it happens.
https://github.com/apache/netbeans/assets/50837574/2161c28a-1210-40c8-8911-c4be2b30378e
The only point I found is in a PHP class of more than 5000 lines, it starts failing when the number of line increases.
It is not only related to the number of lines because change the content of a line can allow it to function or not (without error on the page), even the change of a IF test. This not occured if the file contains less than 5000 lines.

@junichi11
Copy link
Member

It would be nice if you could find and provide an example to reproduce it.

@zeleznypa
Copy link

It also happens to me.

I have my own custom "Code template" with the following code:

    /**
     * ${PARAMETER newVarName default="Parameter"} getter
     *
     * @return ${TYPE newVarName default="Parameter"}
     */
    protected function get${PARAMETER editable=false}(): ${TYPE editable=false}
    {
        return $this->${PROPERTY newVarName default="parameter"};
    }

    /**
     * ${PARAMETER editable=false} setter
     *
     * @param ${TYPE editable=false} $$${PROPERTY editable=false}
     * @return static Provides fluent interface
     */
    protected function set${PARAMETER editable=false}(${TYPE editable=false} $$${PROPERTY editable=false}): static
    {
        $this->${PROPERTY editable=false} = $$${PROPERTY editable=false};
        return $this;
    }

and with the shortcut "getset".

After some work in the normal PHP file, I wrote "getset" + tab, which normally generates the proper code. Sometimes in the same file and after some work, it makes this exception.

messages.log

Sometimes helps to delete all cache files and restart Netbeans and sometimes not :(

It starts with this exception about 2 versions before.

@zeleznypa
Copy link

Another way that lead into the same exception is #4621 (comment)

But there was a problem with not-valid template.
The problem described here before have valid template on valid PHP file :(

@EtienneDelepine
Copy link
Author

This is the detailed error message I get
error netbean insert for.txt

@junichi11 junichi11 removed the needs:triage Requires attention from one of the committers label Jun 1, 2024
@junichi11 junichi11 self-assigned this Jun 1, 2024
junichi11 added a commit to junichi11/netbeans that referenced this issue Jun 1, 2024
- apache#7170
- Add a `null` check
@junichi11
Copy link
Member

Just check null although I can't reproduce this issue. Thanks!

@junichi11 junichi11 added this to the NB23 milestone Jun 1, 2024
@junichi11 junichi11 linked a pull request Jun 1, 2024 that will close this issue
@EtienneDelepine
Copy link
Author

obfuscated.zip
This is a file where the problem occurs in my environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Bug report or fix PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants