This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 57207 - Exceptions <-> ExceptionNames and Interfaces <-> InterfaceNames are not in sync
Summary: Exceptions <-> ExceptionNames and Interfaces <-> InterfaceNames are not in sync
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 4.x
Hardware: All All
: P3 blocker (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-30 15:16 UTC by Jan Becicka
Modified: 2007-09-26 09:14 UTC (History)
2 users (show)

See Also:
Issue Type: TASK
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Becicka 2005-03-30 15:16:45 UTC
Create a new property pattern:
[x] Bound
[x] Constrained
[x] Generate Field
[x] Generate Return Statement
[x] Generate Set Statement
[x] Generate Property Change Support

following methd is generated:
    public void setAsdf(String asdf) {

        String oldAsdf = this.asdf;
        vetoableChangeSupport.fireVetoableChange("asdf", oldAsdf, asdf);
        this.asdf = asdf;
        propertyChangeSupport.firePropertyChange ("asdf", oldAsdf, asdf);
    }

but method header should contain "throws PropertyVetoException". Otherwise the
method is not compilable.
Comment 1 Jan Pokorsky 2005-03-30 15:46:09 UTC
Reproducible but not a bug of the beans module. I have debugged adding a
property and the exception WAS added to the method element but not to the source
file. Here is what the beans module does:

JavaClass declaringClass = getDeclaringClass();
JavaModelPackage jmodel =
  JavaMetamodel.getManager().getJavaExtent(declaringClass);
Method newSetter = jmodel.getMethod().createMethod();
newSetter.setName( "set" + capitalizeFirstLetter( getName() ) ); // NOI18N
newSetter.setType( patternAnalyser.findType("void") ); // NOI18N
newSetter.setModifiers( Modifier.PUBLIC );
Parameter param = jmodel.getParameter().createParameter();
param.setName(name);
param.setType(type);
newSetter.getParameters().add(param);
JavaClass exception = 
  patternAnalyser.findClassElement("java.beans.PropertyVetoException");
newSetter.getExceptions().add(exception);
newSetter.setBodyText( body );
newSetter.setJavadocText( comment );
declaringClass.getFeatures().add(newSetter);
Comment 2 Jan Pokorsky 2005-03-30 15:47:07 UTC
reassigning to proper component
Comment 3 Jan Becicka 2005-03-31 08:28:38 UTC
Problem is, that Exceptions <-> ExceptionNames and Interfaces <-> InterfaceNames
are not synchronized.
Easy workaround is to use 
newSetter.getExceptionNames().add(...) instead of
newSetter.getExceptions().add(...);
Comment 4 Martin Matula 2005-03-31 08:37:24 UTC
Reassigning to Honza to implement the suggested workaround in beans module for
4.1. Please assign back to javacore and update the target milestone to future
once you are done.
Comment 5 Jan Pokorsky 2005-03-31 13:56:21 UTC
I would like to implement the workaround but it seems it does not work in all cases.

1. I replaced code in org/netbeans/modules/beans/beaninfo/BiSuperClass.java

-        m.getExceptions().addAll(orig.getExceptions());
+        m.getExceptionNames().addAll(orig.getExceptionNames());

 but then I get javax.jmi.reflect.CompositionViolationException. How can I
simply duplicate MultipartIds?

2. I replaced code in org.netbeans.modules.beans.EventSetPattern.setIsUnicast

 List/*<JavaClass>*/ exs = addListenerMethod.getExceptions();
 for (Iterator it = exs.iterator(); it.hasNext();) {
    JavaClass ex = (JavaClass) it.next();
    if (tooMany.isSubTypeOf(ex)) {
        MultipartId exId = 
jmodel.getMultipartId().createMultipartId(ex.getName(), null, null);
        remove.add(exId);
    }
 }
 addListenerMethod.getExceptionNames().removeAll(remove);

 After that the exception (tooMany) still remains in source file.

Any idea what is wrong now?
Comment 6 Jan Becicka 2005-03-31 14:08:40 UTC
> How can I simply duplicate MultipartIds?
duplicate() does not work for you?

> but then I get javax.jmi.reflect.CompositionViolationException

It is probably thrown, because you are trying to add Elements from one extend to
different one.

> Any idea what is wrong now?
You are trying to remove different instances of MultipartID than those, which
are in getExceptionNames(). 

Try to do something like this:

List/*<JavaClass>*/ exs = addListenerMethod.getExceptions();
Iterator namesIt = addListenerMethod.getExceptionNames().iterator();
 for (Iterator it = exs.iterator(); it.hasNext();) {
    JavaClass ex = (JavaClass) it.next();
    namesIt.next();
    if (tooMany.isSubTypeOf(ex)) {
       namesIt.remove();
    }
 }
Comment 7 Martin Matula 2005-03-31 14:11:45 UTC
You can use Element.duplicate() method to duplicate elements. (You can write a
simple helper method to duplicate lists of elements). Alternatively you could
make MetadataElement.duplicateList() method public (currently it is package
private) and use that.
If you want to duplicate elements into a different extent, you can use
MetadataElement.duplicate(targetExtent) to do that (MultipartId can be cast to
MetadataElement).
The code in setIsUnicast() does not work because the newly created MultipartId
is not in the list of multipart ids in exception names. You should do the following:
List/*<MultipartId>*/ exs = addListenerMethod.getExceptionNames();
for (Iterator it = exs.iterator(); it.hasNext();) {
    MultipartId exId = (MultipartId) it.next();
    JavaClass ex = (JavaClass) exId.getElement();
    if (tooMany.isSubTypeOf(ex)) {
        remove.add(exId);
    }
 }
 addListenerMethod.getExceptionNames().removeAll(remove);


Comment 8 Jan Pokorsky 2005-03-31 15:38:53 UTC
I know about .duplicate but I need .duplicate(JavaModelPackage). Thanks Martine
I have not been aware of it. It should be part of API IMO.

One more question. If I have to create new MultipartId in order to add
exception/interface it means that there can be several ids representing the same
exception after several iterations. How will they be removed from mdr? In other
words I am missing mapping Element -> MultipartId.
Comment 9 Martin Matula 2005-03-31 15:50:04 UTC
The duplicate(targetExtent) was added quite recently, so we did not want to
change API that late in the release cycle. It should be a regular API in the
next release.

MultipartIds are transient elements (so regular Java garbage collection applies
to them) that represent the identifier in the source code - i.e. for each
occurrence of a given exception in the source code there should be a MultipartId
corresponding to it.

There is one more complication that you should be careful about (sorry, we
should really fix the synchronization issue for the next release).
InterfaceNames and ExceptionNames are not available for classes read from class
file. So if you need to be able to read these also from the class-files, you
should rather read them from getExceptions() and getInterfaces() and create
multipart ids from those rather than trying to duplicate the IDs returned (in
fact not returned :)) from getExceptionNames().
Comment 10 Jan Pokorsky 2005-03-31 16:04:22 UTC
Thanks for clarification.

To XXXNames() methods and class files I hope you are joking. Is it documented
somewhere? I need it to generate the beaninfo since some involved classes may
come from rt.jar. Uff, I am going to rewrite duplicate methods again :-(
Comment 11 Jan Pokorsky 2005-03-31 17:34:13 UTC
workarounded in

/cvs/beans/src/org/netbeans/modules/beans/EventSetPattern.java
new revision: 1.28; previous revision: 1.27
/cvs/beans/src/org/netbeans/modules/beans/IdxPropertyPattern.java
new revision: 1.28; previous revision: 1.27
/cvs/beans/src/org/netbeans/modules/beans/PropertyPattern.java
new revision: 1.36; previous revision: 1.35
/cvs/beans/src/org/netbeans/modules/beans/beaninfo/BiSuperClass.java
new revision: 1.17; previous revision: 1.16
Comment 12 Jan Pokorsky 2005-03-31 17:36:15 UTC
reassigning back to the javacore to fix the root of the problem
Comment 13 Jan Becicka 2005-04-01 05:23:53 UTC
Honzo, thanks for your fix and for your patience.
Comment 14 Jan Becicka 2006-10-26 16:28:04 UTC
Javacore module was replaced by Retouche infrastructure. This bug is not valid
in trunk any more.
Comment 15 Quality Engineering 2007-09-20 12:48:30 UTC
Reorganization of java component