英文:
Netbeans 11.3 doesn't mark as an error the use of a nonexistent class
问题
我在Ubuntu 18.04.4上使用Netbeans 11.3。在进行以下步骤后,我遇到了一个奇怪的问题:
创建一个新的Maven项目(新项目 -> Java with Maven -> Java Application) - 我使用user.xmpl作为我的包名。
在该项目中创建两个类,并添加以下代码:
FirstClass.java:
package user.xmpl;
public class FirstClass {
public FirstClass() {
object.function(() -> {});
}
}
SecondClass.java:
package user.xmpl;
public class SecondClass {
FirstClass testClass;
BadClass badVariable;
}
在BadClass badVariable这一行没有错误消息,也没有在SecondClass文件的其他任何行上出现错误(BadClass未定义)。但整个文件在标签和项目树中被标记为有错误。
只要进行以下任何更改,就会显示错误(如预期):
- 在SecondClass中交换两个定义的顺序
- 删除SecondClass中的第一个定义(FirstClass)
- 删除FirstClass的构造函数
- 删除FirstClass中的一行代码(object.function)
- 从FirstClass的代码行中删除lambda表达式
- 使用Java Ant项目代替Maven项目
当然,在object.function这一行存在错误,但是如果通过适当定义object和function来修复该错误,问题不会改变。为了隔离问题,我已删除了任何多余的代码。
是否有人知道为什么BadClass badVariable这一行没有显示错误?这是Netbeans的一个错误吗?如果是,我应该如何报告?是否有人可以确认在他们的系统上也会出现这个问题?
英文:
I'm using Netbeans 11.3 on Ubuntu 18.04.4. I've run into a strange issue that becomes visible after doing the following steps:
Create a new Maven Project (New Project -> Java with Maven -> Java Application) - I use user.xmpl as my package name.
Create two classes in that project, with the following code:
FirstClass.java:
package user.xmpl;
public class FirstClass {
public FirstClass() {
object.function(() -> {});
}
}
SecondClass.java:
package user.xmpl;
public class SecondClass {
FirstClass testClass;
BadClass badVariable;
}
There is no error message on the BadClass badVariable line, nor on any other line in the SecondClass file (BadClass is not defined). The file as a whole is marked as having an error, in the tab and in the Project tree.
The error is shown (as expected) with any of the following changes:
- Switch the order of the two definitions within SecondClass
- Delete the first definition (FirstClass) in SecondClass
- Delete the constructor of FirstClass
- Delete the one line in FirstClass (object.function)
- Remove the lambda expression from the line in FirstClass
- Use a Java Ant project instead of a Maven one
There is, of course, an error on the object.function line, but there is no change in the issue if that error is fixed by appropriately defining object and function. I removed any extraneous code to help isolate the issue.
Does anyone have any idea why no errors show up on the BadClass badVariable line? Is this a bug in Netbeans, and if so how should I report it? Can anyone confirm that this happens on their system?
专注分享java语言的经验与见解,让所有开发者获益!
评论