Skip to content

Commit a2d2906

Browse files
Enterprise: Fix multiple places where null values could be encountered and are not protected
Observed exception: java.lang.NullPointerException: Cannot invoke "org.netbeans.api.j2ee.core.Profile.isAtMost(org.netbeans.api.j2ee.core.Profile)" because "profile" is null at org.netbeans.modules.websvc.rest.editor.AsyncConverter.isApplicable(AsyncConverter.java:98) at org.netbeans.modules.websvc.rest.editor.AsyncConverterTask.run(AsyncConverterTask.java:61) at org.netbeans.modules.websvc.rest.editor.AsyncConverterTask.run(AsyncConverterTask.java:52) [catch] at org.netbeans.modules.java.source.JavaSourceAccessor$CancelableTaskWrapper.run(JavaSourceAccessor.java:273) at org.netbeans.modules.parsing.impl.TaskProcessor.callParserResultTask(TaskProcessor.java:561) at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.run(TaskProcessor.java:786) at org.openide.util.lookup.Lookups.executeWith(Lookups.java:288) at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.execute(TaskProcessor.java:702) at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:663) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1403) at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45) at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2018)
1 parent b1a4514 commit a2d2906

File tree

14 files changed

+47
-42
lines changed

14 files changed

+47
-42
lines changed

enterprise/j2ee.ejbcore/src/org/netbeans/modules/j2ee/ejbcore/ejb/wizard/dd/EjbJarXmlWizardIterator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,17 @@ public Set instantiate() throws IOException {
9494
String resource;
9595
// see #213631 - caused by fact that EJB DD schemas have different numbering than WEB DD schemas
9696
// (so Java EE6 Web-DD is of the version 3.0, but Ejb-DD is of the version 3.1)
97-
if (j2eeProfile.isAtLeast(Profile.JAKARTA_EE_9_WEB)) {
97+
if (j2eeProfile != null && j2eeProfile.isAtLeast(Profile.JAKARTA_EE_9_WEB)) {
9898
resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-4.0.xml";
99-
} else if (j2eeProfile.isAtLeast(Profile.JAVA_EE_7_WEB)) {
99+
} else if (j2eeProfile != null && j2eeProfile.isAtLeast(Profile.JAVA_EE_7_WEB)) {
100100
resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-3.2.xml";
101-
} else if (j2eeProfile.isAtLeast(Profile.JAVA_EE_6_WEB)) {
101+
} else if (j2eeProfile != null && j2eeProfile.isAtLeast(Profile.JAVA_EE_6_WEB)) {
102102
// ee6 web module is of the version 3.0 but the ee6 deployment descriptor schema should be of version 3.1
103103
resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-3.1.xml";
104-
} else {
104+
} else if (j2eeModule != null) {
105105
resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-" + j2eeModule.getModuleVersion() + ".xml";
106+
} else {
107+
return Collections.EMPTY_SET;
106108
}
107109
FileObject source = FileUtil.getConfigFile(resource);
108110
if (source == null) {

enterprise/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/jaxws/EjbProjectJAXWSClientSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected FileObject getXmlArtifactsRoot() {
8686
@Override
8787
protected String getProjectJavaEEVersion() {
8888
EjbJar ejbModule = EjbJar.getEjbJar(project.getProjectDirectory());
89-
if (ejbModule != null) {
89+
if (ejbModule != null && ejbModule.getJ2eeProfile() != null) {
9090
switch (ejbModule.getJ2eeProfile()) {
9191
case JAVA_EE_6_WEB:
9292
case JAVA_EE_6_FULL:

enterprise/j2ee.ejbjarproject/src/org/netbeans/modules/j2ee/ejbjarproject/jaxws/EjbProjectJAXWSSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private void logWsDetected() {
157157
@Override
158158
protected String getProjectJavaEEVersion() {
159159
EjbJar ejbModule = EjbJar.getEjbJar(project.getProjectDirectory());
160-
if (ejbModule != null) {
160+
if (ejbModule != null && ejbModule.getJ2eeProfile() != null) {
161161
switch (ejbModule.getJ2eeProfile()) {
162162
case JAVA_EE_6_WEB:
163163
case JAVA_EE_6_FULL:

enterprise/j2ee.ejbverification/src/org/netbeans/modules/j2ee/ejbverification/rules/PersistentTimerInEjbLite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public static Collection<ErrorDescription> run(HintContext hintContext) {
8484
final EJBProblemContext ctx = HintsUtils.getOrCacheContext(hintContext);
8585
if (ctx != null && ctx.getEjb() instanceof Session) {
8686
final Profile profile = ctx.getEjbModule().getJ2eeProfile();
87-
boolean ee9lite = profile.isAtLeast(Profile.JAKARTA_EE_9_WEB);
88-
boolean ee7lite = profile.isAtLeast(Profile.JAVA_EE_7_WEB);
89-
boolean ee6lite = (profile == Profile.JAVA_EE_6_WEB);
87+
boolean ee9lite = profile != null && profile.isAtLeast(Profile.JAKARTA_EE_9_WEB);
88+
boolean ee7lite = profile != null && profile.isAtLeast(Profile.JAVA_EE_7_WEB);
89+
boolean ee6lite = profile == Profile.JAVA_EE_6_WEB;
9090
J2eePlatform platform = ProjectUtil.getPlatform(ctx.getProject());
9191
if ((ee6lite || ee7lite || ee9lite) && nonEeFullServer(platform)) {
9292
for (Element element : ctx.getClazz().getEnclosedElements()) {

enterprise/web.project/src/org/netbeans/modules/web/project/api/WebProjectUtilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ private static AntProjectHelper setupProject(FileObject dirFO, String name,
836836

837837
public static void upgradeJ2EEProfile(WebProject project){
838838
Profile profile = project.getAPIEjbJar().getJ2eeProfile();
839-
if (profile.isWebProfile() && profile.isAtLeast(Profile.JAVA_EE_6_WEB)) {
839+
if (profile != null && profile.isWebProfile() && profile.isAtLeast(Profile.JAVA_EE_6_WEB)) {
840840
//check the J2EE 6/7 Full profile specific functionality
841841
Boolean isFullRequired = Boolean.FALSE;
842842
try{

enterprise/web.project/src/org/netbeans/modules/web/project/jaxws/WebProjectJAXWSClientSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected FileObject getXmlArtifactsRoot() {
109109
@Override
110110
protected String getProjectJavaEEVersion() {
111111
WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
112-
if (webModule != null) {
112+
if (webModule != null && webModule.getJ2eeProfile() != null) {
113113
switch (webModule.getJ2eeProfile()) {
114114
case JAVA_EE_6_WEB:
115115
case JAVA_EE_6_FULL:

enterprise/web.project/src/org/netbeans/modules/web/project/jaxws/WebProjectJAXWSSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ private void logWsDetected() {
594594
@Override
595595
protected String getProjectJavaEEVersion() {
596596
WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
597-
if (webModule != null) {
597+
if (webModule != null && webModule.getJ2eeProfile() != null) {
598598
switch (webModule.getJ2eeProfile()) {
599599
case JAVA_EE_6_WEB:
600600
case JAVA_EE_6_FULL:

enterprise/web.project/src/org/netbeans/modules/web/project/ui/customizer/WebProjectProperties.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -375,30 +375,32 @@ private void init() {
375375
PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer();
376376
SpecificationVersion minimalSourceLevel = null;
377377
Profile profile = Profile.fromPropertiesString(evaluator.getProperty(J2EE_PLATFORM));
378-
switch (profile) {
379-
case JAKARTA_EE_11_FULL:
380-
minimalSourceLevel = new SpecificationVersion("21");
381-
break;
382-
case JAKARTA_EE_10_FULL:
383-
case JAKARTA_EE_9_1_FULL:
384-
minimalSourceLevel = new SpecificationVersion("11");
385-
break;
386-
case JAKARTA_EE_9_FULL:
387-
case JAKARTA_EE_8_FULL:
388-
case JAVA_EE_8_FULL:
389-
minimalSourceLevel = new SpecificationVersion("1.8");
390-
break;
391-
case JAVA_EE_7_FULL:
392-
minimalSourceLevel = new SpecificationVersion("1.7");
393-
break;
394-
case JAVA_EE_6_FULL:
395-
minimalSourceLevel = new SpecificationVersion("1.6");
396-
break;
397-
case JAVA_EE_5:
398-
minimalSourceLevel = new SpecificationVersion("1.5");
399-
break;
400-
default:
401-
break;
378+
if (profile != null) {
379+
switch (profile) {
380+
case JAKARTA_EE_11_FULL:
381+
minimalSourceLevel = new SpecificationVersion("21");
382+
break;
383+
case JAKARTA_EE_10_FULL:
384+
case JAKARTA_EE_9_1_FULL:
385+
minimalSourceLevel = new SpecificationVersion("11");
386+
break;
387+
case JAKARTA_EE_9_FULL:
388+
case JAKARTA_EE_8_FULL:
389+
case JAVA_EE_8_FULL:
390+
minimalSourceLevel = new SpecificationVersion("1.8");
391+
break;
392+
case JAVA_EE_7_FULL:
393+
minimalSourceLevel = new SpecificationVersion("1.7");
394+
break;
395+
case JAVA_EE_6_FULL:
396+
minimalSourceLevel = new SpecificationVersion("1.6");
397+
break;
398+
case JAVA_EE_5:
399+
minimalSourceLevel = new SpecificationVersion("1.5");
400+
break;
401+
default:
402+
break;
403+
}
402404
}
403405
JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET), minimalSourceLevel);
404406
JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer ();

enterprise/websocket/src/org/netbeans/modules/websocket/editor/WebSocketMethodsTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ private boolean isApplicable(FileObject fileObject) {
124124
return false;
125125
}
126126
Profile profile = webModule.getJ2eeProfile();
127-
if (profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
127+
if (profile != null && profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
128128
return false;
129129
}
130130
return true;

enterprise/websocket/src/org/netbeans/modules/websocket/wizard/WebSocketPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public boolean isValid() {
7878
WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
7979
if (webModule != null) {
8080
Profile profile = webModule.getJ2eeProfile();
81-
if (profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
81+
if (profile != null && profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
8282
setErrorMessage(NbBundle.getMessage(WebSocketPanel.class,
8383
"MSG_NoJEE7Profile")); // NOI18N
8484
return false;

0 commit comments

Comments
 (0)