Author: akazakov
Date: 2010-12-19 19:37:34 -0500 (Sun, 19 Dec 2010)
New Revision: 27604
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
Log:
https://issues.jboss.org/browse/JBIDE-7952 Fixed NPE
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-19
22:47:26 UTC (rev 27603)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-20
00:37:34 UTC (rev 27604)
@@ -998,7 +998,7 @@
String bindedErrorMessage = NLS.bind(errorMessage, new
String[]{method.getMethod().getElementName(), bean.getBeanClass().getElementName()});
addError(bindedErrorMessage, preferencesKey, declaration, bean.getResource(), id);
}
- } else if (iMethod != method.getMethod()) {
+ } else if (iMethod != method.getMethod() && !iMethod.isBinary()) {
getValidationContext().addLinkedCoreResource(bean.getSourcePath().toOSString(),
iMethod.getResource().getFullPath(), false);
}
}
@@ -1172,7 +1172,7 @@
String bindedErrorMessage =
NLS.bind(CDIValidationMessages.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, new
String[]{producerMethod.getMethod().getElementName(),
producer.getBeanClass().getElementName()});
addError(bindedErrorMessage,
CDIPreferences.ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN, producer.getProducesAnnotation(),
producer.getResource(), ILLEGAL_PRODUCER_METHOD_IN_SESSION_BEAN_ID);
saveAllSuperTypesAsLinkedResources(classBean);
- } else if (method != producerMethod.getMethod()) {
+ } else if (method != producerMethod.getMethod() && !method.isReadOnly()) {
getValidationContext().addLinkedCoreResource(classBean.getSourcePath().toOSString(),
method.getResource().getFullPath(), false);
}
}
@@ -1334,104 +1334,106 @@
addError(CDIValidationMessages.AMBIGUOUS_INJECTION_POINTS,
CDIPreferences.AMBIGUOUS_INJECTION_POINTS, reference, injection.getResource());
} else if(beans.size()==1) {
IBean bean = beans.iterator().next();
- getValidationContext().addLinkedCoreResource(injection.getSourcePath().toOSString(),
bean.getResource().getFullPath(), false);
- /*
- * 5.2.4. Primitive types and null values
- * - injection point of primitive type resolves to a bean that may have null values,
such as a producer method with a non-primitive return type or a producer field with a
non-primitive type
- */
- if(bean.isNullable() && injection.getType()!=null &&
injection.getType().isPrimitive()) {
- addError(CDIValidationMessages.INJECT_RESOLVES_TO_NULLABLE_BEAN,
CDIPreferences.INJECT_RESOLVES_TO_NULLABLE_BEAN, reference, injection.getResource());
- }
- /*
- * 5.1.4. Inter-module injection
- * - a decorator can not be injected
- * - an interceptor can not be injected
- */
- if(bean instanceof IDecorator) {
- addError(CDIValidationMessages.INJECTED_DECORATOR,
CDIPreferences.INJECTED_DECORATOR, reference, injection.getResource());
- } else if(bean instanceof IInterceptor) {
- addError(CDIValidationMessages.INJECTED_INTERCEPTOR,
CDIPreferences.INJECTED_INTERCEPTOR, reference, injection.getResource());
- }
- /*
- * 5.4.1. Unproxyable bean types
- * - If an injection point whose declared type cannot be proxied by the container
resolves to a bean with a normal scope,
- * the container automatically detects the problem and treats it as a deployment
problem.
- */
- if(bean.getScope().isNorlmalScope() && injection.getType()!=null) {
- // - Array types cannot be proxied by the container.
- String typeSignature = injection.getType().getSignature();
- int kind = Signature.getTypeSignatureKind(typeSignature);
- if(kind == Signature.ARRAY_TYPE_SIGNATURE) {
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_ARRAY_TYPE,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- } else if(injection.getType().isPrimitive()) {
- // - Primitive types cannot be proxied by the container.
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_PRIMITIVE_TYPE,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- } else if(bean instanceof IClassBean) {
- try {
- if(Flags.isFinal(bean.getBeanClass().getFlags())) {
- // - Classes which are declared final cannot be proxied by the container.
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_FINAL_TYPE,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- } else {
- IMethod[] methods = bean.getBeanClass().getMethods();
- boolean hasDefaultConstructor = false;
- for (IMethod method : methods) {
- hasDefaultConstructor = hasDefaultConstructor || (method.isConstructor()
&& !Flags.isPrivate(method.getFlags()) &&
method.getParameterNames().length==0);
- if(Flags.isFinal(method.getFlags())) {
- // - Classes which have final methods cannot be proxied by the container.
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_FM,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- hasDefaultConstructor = true;
- break;
+ if(!bean.getBeanClass().isReadOnly()) {
+ getValidationContext().addLinkedCoreResource(injection.getSourcePath().toOSString(),
bean.getResource().getFullPath(), false);
+ /*
+ * 5.2.4. Primitive types and null values
+ * - injection point of primitive type resolves to a bean that may have null
values, such as a producer method with a non-primitive return type or a producer field
with a non-primitive type
+ */
+ if(bean.isNullable() && injection.getType()!=null &&
injection.getType().isPrimitive()) {
+ addError(CDIValidationMessages.INJECT_RESOLVES_TO_NULLABLE_BEAN,
CDIPreferences.INJECT_RESOLVES_TO_NULLABLE_BEAN, reference, injection.getResource());
+ }
+ /*
+ * 5.1.4. Inter-module injection
+ * - a decorator can not be injected
+ * - an interceptor can not be injected
+ */
+ if(bean instanceof IDecorator) {
+ addError(CDIValidationMessages.INJECTED_DECORATOR,
CDIPreferences.INJECTED_DECORATOR, reference, injection.getResource());
+ } else if(bean instanceof IInterceptor) {
+ addError(CDIValidationMessages.INJECTED_INTERCEPTOR,
CDIPreferences.INJECTED_INTERCEPTOR, reference, injection.getResource());
+ }
+ /*
+ * 5.4.1. Unproxyable bean types
+ * - If an injection point whose declared type cannot be proxied by the container
resolves to a bean with a normal scope,
+ * the container automatically detects the problem and treats it as a deployment
problem.
+ */
+ if(bean.getScope().isNorlmalScope() && injection.getType()!=null) {
+ // - Array types cannot be proxied by the container.
+ String typeSignature = injection.getType().getSignature();
+ int kind = Signature.getTypeSignatureKind(typeSignature);
+ if(kind == Signature.ARRAY_TYPE_SIGNATURE) {
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_ARRAY_TYPE,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ } else if(injection.getType().isPrimitive()) {
+ // - Primitive types cannot be proxied by the container.
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_PRIMITIVE_TYPE,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ } else if(bean instanceof IClassBean) {
+ try {
+ if(Flags.isFinal(bean.getBeanClass().getFlags())) {
+ // - Classes which are declared final cannot be proxied by the container.
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_FINAL_TYPE,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ } else {
+ IMethod[] methods = bean.getBeanClass().getMethods();
+ boolean hasDefaultConstructor = false;
+ for (IMethod method : methods) {
+ hasDefaultConstructor = hasDefaultConstructor || (method.isConstructor()
&& !Flags.isPrivate(method.getFlags()) &&
method.getParameterNames().length==0);
+ if(Flags.isFinal(method.getFlags())) {
+ // - Classes which have final methods cannot be proxied by the container.
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_FM,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ hasDefaultConstructor = true;
+ break;
+ }
}
+ if(!hasDefaultConstructor) {
+ // - Classes which don't have a non-private constructor with no parameters
cannot be proxied by the container.
+ addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_NPC,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
+ }
}
- if(!hasDefaultConstructor) {
- // - Classes which don't have a non-private constructor with no parameters
cannot be proxied by the container.
- addError(MessageFormat.format(CDIValidationMessages.UNPROXYABLE_BEAN_TYPE_WITH_NPC,
injection.getType().getSimpleName(), bean.getSimpleJavaName()),
CDIPreferences.UNPROXYABLE_BEAN_TYPE, reference, injection.getResource());
- }
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
}
- } catch (JavaModelException e) {
- CDICorePlugin.getDefault().logError(e);
}
}
- }
- if(injection.getClassBean() instanceof IDecorator && injection.isDelegate()
&& bean instanceof IClassBean) {
- try {
- IType beanClass = bean.getBeanClass();
- if(Flags.isFinal(beanClass.getFlags())) {
- // 8.3. Decorator resolution
- // - If a decorator matches a managed bean, and the managed bean class is declared
final, the container automatically detects
- // the problem and treats it as a deployment problem.
- addError(MessageFormat.format(CDIValidationMessages.DECORATOR_RESOLVES_TO_FINAL_CLASS,
bean.getSimpleJavaName()), CDIPreferences.DECORATOR_RESOLVES_TO_FINAL_BEAN, reference,
injection.getResource());
- } else {
- // 8.3. Decorator resolution
- // - If a decorator matches a managed bean with a non-static, non-private, final
method, and the decorator also implements that method,
- // the container automatically detects the problem and treats it as a
deployment problem.
- IType decoratorClass = injection.getClassBean().getBeanClass();
- IMethod[] methods = decoratorClass.getMethods();
- boolean reported = false;
- if(methods!=null) {
- for (IMethod method : methods) {
- if(!Flags.isPrivate(method.getFlags()) &&
!Flags.isStatic(method.getFlags())) {
- IMethod[] beanMethods = beanClass.findMethods(method);
- if(beanMethods!=null) {
- for (IMethod beanMethod : beanMethods) {
- int flags = beanMethod.getFlags();
- if(!Flags.isPrivate(flags) && !Flags.isStatic(flags) &&
Flags.isFinal(flags)) {
- String methodName = Signature.toString(beanMethod.getSignature(),
beanMethod.getElementName(), beanMethod.getParameterNames(), false, false);
- addError(MessageFormat.format(CDIValidationMessages.DECORATOR_RESOLVES_TO_FINAL_METHOD,
bean.getSimpleJavaName(), methodName), CDIPreferences.DECORATOR_RESOLVES_TO_FINAL_BEAN,
reference, injection.getResource());
- reported = true;
+ if(injection.getClassBean() instanceof IDecorator && injection.isDelegate()
&& bean instanceof IClassBean) {
+ try {
+ IType beanClass = bean.getBeanClass();
+ if(Flags.isFinal(beanClass.getFlags())) {
+ // 8.3. Decorator resolution
+ // - If a decorator matches a managed bean, and the managed bean class is
declared final, the container automatically detects
+ // the problem and treats it as a deployment problem.
+ addError(MessageFormat.format(CDIValidationMessages.DECORATOR_RESOLVES_TO_FINAL_CLASS,
bean.getSimpleJavaName()), CDIPreferences.DECORATOR_RESOLVES_TO_FINAL_BEAN, reference,
injection.getResource());
+ } else {
+ // 8.3. Decorator resolution
+ // - If a decorator matches a managed bean with a non-static, non-private, final
method, and the decorator also implements that method,
+ // the container automatically detects the problem and treats it as a
deployment problem.
+ IType decoratorClass = injection.getClassBean().getBeanClass();
+ IMethod[] methods = decoratorClass.getMethods();
+ boolean reported = false;
+ if(methods!=null) {
+ for (IMethod method : methods) {
+ if(!Flags.isPrivate(method.getFlags()) &&
!Flags.isStatic(method.getFlags())) {
+ IMethod[] beanMethods = beanClass.findMethods(method);
+ if(beanMethods!=null) {
+ for (IMethod beanMethod : beanMethods) {
+ int flags = beanMethod.getFlags();
+ if(!Flags.isPrivate(flags) && !Flags.isStatic(flags) &&
Flags.isFinal(flags)) {
+ String methodName = Signature.toString(beanMethod.getSignature(),
beanMethod.getElementName(), beanMethod.getParameterNames(), false, false);
+ addError(MessageFormat.format(CDIValidationMessages.DECORATOR_RESOLVES_TO_FINAL_METHOD,
bean.getSimpleJavaName(), methodName), CDIPreferences.DECORATOR_RESOLVES_TO_FINAL_BEAN,
reference, injection.getResource());
+ reported = true;
+ break;
+ }
+ }
+ if(reported) {
break;
}
}
- if(reported) {
- break;
- }
}
}
}
}
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
}
- } catch (JavaModelException e) {
- CDICorePlugin.getDefault().logError(e);
}
}
}