Skip to content

Commit

Permalink
Merge pull request #7603 from matthiasblaesing/null_checks_enterprise
Browse files Browse the repository at this point in the history
Enterprise: Fix multiple places where null values could be encountered and are not protected
  • Loading branch information
matthiasblaesing authored Jul 25, 2024
2 parents 573b1dc + a2d2906 commit b2b45ae
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,17 @@ public Set instantiate() throws IOException {
String resource;
// see #213631 - caused by fact that EJB DD schemas have different numbering than WEB DD schemas
// (so Java EE6 Web-DD is of the version 3.0, but Ejb-DD is of the version 3.1)
if (j2eeProfile.isAtLeast(Profile.JAKARTA_EE_9_WEB)) {
if (j2eeProfile != null && j2eeProfile.isAtLeast(Profile.JAKARTA_EE_9_WEB)) {
resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-4.0.xml";
} else if (j2eeProfile.isAtLeast(Profile.JAVA_EE_7_WEB)) {
} else if (j2eeProfile != null && j2eeProfile.isAtLeast(Profile.JAVA_EE_7_WEB)) {
resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-3.2.xml";
} else if (j2eeProfile.isAtLeast(Profile.JAVA_EE_6_WEB)) {
} else if (j2eeProfile != null && j2eeProfile.isAtLeast(Profile.JAVA_EE_6_WEB)) {
// ee6 web module is of the version 3.0 but the ee6 deployment descriptor schema should be of version 3.1
resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-3.1.xml";
} else {
} else if (j2eeModule != null) {
resource = "org-netbeans-modules-j2ee-ejbjarproject/ejb-jar-" + j2eeModule.getModuleVersion() + ".xml";
} else {
return Collections.EMPTY_SET;
}
FileObject source = FileUtil.getConfigFile(resource);
if (source == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected FileObject getXmlArtifactsRoot() {
@Override
protected String getProjectJavaEEVersion() {
EjbJar ejbModule = EjbJar.getEjbJar(project.getProjectDirectory());
if (ejbModule != null) {
if (ejbModule != null && ejbModule.getJ2eeProfile() != null) {
switch (ejbModule.getJ2eeProfile()) {
case JAVA_EE_6_WEB:
case JAVA_EE_6_FULL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void logWsDetected() {
@Override
protected String getProjectJavaEEVersion() {
EjbJar ejbModule = EjbJar.getEjbJar(project.getProjectDirectory());
if (ejbModule != null) {
if (ejbModule != null && ejbModule.getJ2eeProfile() != null) {
switch (ejbModule.getJ2eeProfile()) {
case JAVA_EE_6_WEB:
case JAVA_EE_6_FULL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public static Collection<ErrorDescription> run(HintContext hintContext) {
final EJBProblemContext ctx = HintsUtils.getOrCacheContext(hintContext);
if (ctx != null && ctx.getEjb() instanceof Session) {
final Profile profile = ctx.getEjbModule().getJ2eeProfile();
boolean ee9lite = profile.isAtLeast(Profile.JAKARTA_EE_9_WEB);
boolean ee7lite = profile.isAtLeast(Profile.JAVA_EE_7_WEB);
boolean ee6lite = (profile == Profile.JAVA_EE_6_WEB);
boolean ee9lite = profile != null && profile.isAtLeast(Profile.JAKARTA_EE_9_WEB);
boolean ee7lite = profile != null && profile.isAtLeast(Profile.JAVA_EE_7_WEB);
boolean ee6lite = profile == Profile.JAVA_EE_6_WEB;
J2eePlatform platform = ProjectUtil.getPlatform(ctx.getProject());
if ((ee6lite || ee7lite || ee9lite) && nonEeFullServer(platform)) {
for (Element element : ctx.getClazz().getEnclosedElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ private static AntProjectHelper setupProject(FileObject dirFO, String name,

public static void upgradeJ2EEProfile(WebProject project){
Profile profile = project.getAPIEjbJar().getJ2eeProfile();
if (profile.isWebProfile() && profile.isAtLeast(Profile.JAVA_EE_6_WEB)) {
if (profile != null && profile.isWebProfile() && profile.isAtLeast(Profile.JAVA_EE_6_WEB)) {
//check the J2EE 6/7 Full profile specific functionality
Boolean isFullRequired = Boolean.FALSE;
try{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected FileObject getXmlArtifactsRoot() {
@Override
protected String getProjectJavaEEVersion() {
WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
if (webModule != null) {
if (webModule != null && webModule.getJ2eeProfile() != null) {
switch (webModule.getJ2eeProfile()) {
case JAVA_EE_6_WEB:
case JAVA_EE_6_FULL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ private void logWsDetected() {
@Override
protected String getProjectJavaEEVersion() {
WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
if (webModule != null) {
if (webModule != null && webModule.getJ2eeProfile() != null) {
switch (webModule.getJ2eeProfile()) {
case JAVA_EE_6_WEB:
case JAVA_EE_6_FULL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,30 +375,32 @@ private void init() {
PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer();
SpecificationVersion minimalSourceLevel = null;
Profile profile = Profile.fromPropertiesString(evaluator.getProperty(J2EE_PLATFORM));
switch (profile) {
case JAKARTA_EE_11_FULL:
minimalSourceLevel = new SpecificationVersion("21");
break;
case JAKARTA_EE_10_FULL:
case JAKARTA_EE_9_1_FULL:
minimalSourceLevel = new SpecificationVersion("11");
break;
case JAKARTA_EE_9_FULL:
case JAKARTA_EE_8_FULL:
case JAVA_EE_8_FULL:
minimalSourceLevel = new SpecificationVersion("1.8");
break;
case JAVA_EE_7_FULL:
minimalSourceLevel = new SpecificationVersion("1.7");
break;
case JAVA_EE_6_FULL:
minimalSourceLevel = new SpecificationVersion("1.6");
break;
case JAVA_EE_5:
minimalSourceLevel = new SpecificationVersion("1.5");
break;
default:
break;
if (profile != null) {
switch (profile) {
case JAKARTA_EE_11_FULL:
minimalSourceLevel = new SpecificationVersion("21");
break;
case JAKARTA_EE_10_FULL:
case JAKARTA_EE_9_1_FULL:
minimalSourceLevel = new SpecificationVersion("11");
break;
case JAKARTA_EE_9_FULL:
case JAKARTA_EE_8_FULL:
case JAVA_EE_8_FULL:
minimalSourceLevel = new SpecificationVersion("1.8");
break;
case JAVA_EE_7_FULL:
minimalSourceLevel = new SpecificationVersion("1.7");
break;
case JAVA_EE_6_FULL:
minimalSourceLevel = new SpecificationVersion("1.6");
break;
case JAVA_EE_5:
minimalSourceLevel = new SpecificationVersion("1.5");
break;
default:
break;
}
}
JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE), evaluator.getProperty(JAVAC_TARGET), minimalSourceLevel);
JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private boolean isApplicable(FileObject fileObject) {
return false;
}
Profile profile = webModule.getJ2eeProfile();
if (profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
if (profile != null && profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean isValid() {
WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
if (webModule != null) {
Profile profile = webModule.getJ2eeProfile();
if (profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
if (profile != null && profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
setErrorMessage(NbBundle.getMessage(WebSocketPanel.class,
"MSG_NoJEE7Profile")); // NOI18N
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ boolean isApplicable(FileObject fileObject){
return false;
}
Profile profile = webModule.getJ2eeProfile();
if (profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
if (profile != null && profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public boolean isValid() {
WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
if (webModule != null) {
Profile profile = webModule.getJ2eeProfile();
if (profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
if (profile != null && profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
setErrorMessage(NbBundle.getMessage(InterceptorPanel.class,
"MSG_NoJEE7Profile")); // NOI18N
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public boolean isValid() {
WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
if (webModule != null) {
Profile profile = webModule.getJ2eeProfile();
if (profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
if (profile != null && profile.isAtMost(Profile.JAVA_EE_6_FULL)) {
setErrorMessage(NbBundle.getMessage(JaxRsFilterPanel.class,
"MSG_NoJEE7Profile")); // NOI18N
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ public boolean isEESpecWithJaxRS(){
boolean isJee6 = Profile.JAVA_EE_6_WEB.equals(profile) ||
Profile.JAVA_EE_6_FULL.equals(profile);
// Fix for BZ#216345: JAVA_EE_6_WEB profile doesn't contain JAX-RS API
return (isJee6 && MiscPrivateUtilities.supportsTargetProfile(project, Profile.JAVA_EE_6_FULL)) || profile.isAtLeast(Profile.JAVA_EE_7_WEB);
return (isJee6 && MiscPrivateUtilities.supportsTargetProfile(project, Profile.JAVA_EE_6_FULL))
|| (profile != null && profile.isAtLeast(Profile.JAVA_EE_7_WEB));
}

/**
Expand Down

0 comments on commit b2b45ae

Please sign in to comment.