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 72704 - No way to generate annotations with unnamed [] element
Summary: No way to generate annotations with unnamed [] element
Status: VERIFIED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
Depends on:
Blocks: 72219
  Show dependency tree
 
Reported: 2006-02-16 00:53 UTC by Rochelle Raccah
Modified: 2007-09-26 09:14 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
CCE (2.58 KB, text/plain)
2006-02-17 13:32 UTC, Pavel Flaska
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rochelle Raccah 2006-02-16 00:53:25 UTC
I'm trying to generate annotations for EJB 3 of the form:
  @javax.persistence.NamedQueries({
    @javax.persistence.NamedQuery(name="a" query="b"),
    @javax.persistence.NamedQuery(name="c" query="d")
  })

I can't seem to do this with the attribute value and name support within JMI.  I
can do the NamedQuery internal ones, but keep getting exceptions when trying to
generate them inside a NamedQueries annotation.

Here is an excerpt of a discussion on this with Pavel:
>This is what I tried:

>ArrayList nqs = new ArrayList();

>AttributeValue nqAV = JMIGenerationUtil.createAttributeValue(javaClass, "name", 
>"Foo"); //NOI18N
>Annotation nqA = JMIGenerationUtil.createAnnotation(javaClass, 
>"javax.persistence.NamedQuery", Collections.singletonList(nqAV)); //NOI18N
>nqs.add(nqA);

>AttributeValue nqsAV = JMIGenerationUtil.createAttributeValue(javaClass, 
>"value", nqs); //NOI18N
>Annotation nqsA = JMIGenerationUtil.createAnnotation(javaClass, 
>"javax.persistence.NamedQueries", Collections.singletonList(nqsAV)); //NOI18N
>javaClass.getAnnotations().add(nqsA);

>But it does not work.
Comment 1 Pavel Buzek 2006-02-16 01:04:22 UTC
trying to assign to a "JMI" component (hope this is the right one)
Comment 2 Pavel Flaska 2006-02-16 16:51:26 UTC
Seems like problem in javacore.
Comment 3 Pavel Flaska 2006-02-17 13:32:40 UTC
Created attachment 28918 [details]
CCE
Comment 4 Pavel Flaska 2006-02-17 14:56:27 UTC
Fixed CCE in trunk. Added tests:
i) generating annotation with array attribute,
ii) generating annotation with array attribute without attributes names.

Checking in
src/org/netbeans/modules/javacore/jmiimpl/javamodel/ArrayInitializationImpl.java;
/cvs/java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/ArrayInitializationImpl.java,v
 <--  ArrayInitializationImpl.java
new revision: 1.7; previous revision: 1.6
done
Checking in test/cfg-unit.xml;
/cvs/java/javacore/test/cfg-unit.xml,v  <--  cfg-unit.xml
new revision: 1.49; previous revision: 1.48
done
RCS file:
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotationWithoutAttrName_ArrayAttrValueClass.pass,v
done
Checking in
test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotationWithoutAttrName_ArrayAttrValueClass.pass;
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotationWithoutAttrName_ArrayAttrValueClass.pass,v
 <--  testAddAnnotationWithoutAttrName_ArrayAttrValueClass.pass
initial revision: 1.1
done
RCS file:
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotation_ArrayAttrValueClass.pass,v
done
Checking in
test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotation_ArrayAttrValueClass.pass;
/cvs/java/javacore/test/unit/data/goldenfiles/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest/testAddAnnotation_ArrayAttrValueClass.pass,v
 <--  testAddAnnotation_ArrayAttrValueClass.pass
initial revision: 1.1
done
RCS file:
/cvs/java/javacore/test/unit/data/projects/default/src/org/netbeans/test/codegen/ArrayAttrValueClass.java,v
done
Checking in
test/unit/data/projects/default/src/org/netbeans/test/codegen/ArrayAttrValueClass.java;
/cvs/java/javacore/test/unit/data/projects/default/src/org/netbeans/test/codegen/ArrayAttrValueClass.java,v
 <--  ArrayAttrValueClass.java
initial revision: 1.1
done
RCS file:
/cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest.java,v
done
Checking in
test/unit/src/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest.java;
/cvs/java/javacore/test/unit/src/org/netbeans/jmi/javamodel/codegen/ArrayAttrValueTest.java,v
 <--  ArrayAttrValueTest.java
initial revision: 1.1
done
Comment 5 Pavel Flaska 2006-02-17 15:07:45 UTC
Leaving opened as Pavel B. reported InvalidObjectException when he tried it with
previous fix. Not sure where the problem is, I will continue investigating it.
Comment 6 Pavel Flaska 2006-02-20 15:36:46 UTC
Cannot reproduce InvalidObjectException in my tests. Rochelle, can you, please,
test it and provide description of steps to reproduce? -- Currently, it does not
seem to me it's still connected with annotations. In addition to, generated
source could be also valueable. Thanks.
Comment 7 Rochelle Raccah 2006-02-22 02:29:28 UTC
I don't get the exception Pavel got, but I get 2 others:
     [exec] [org.netbeans.mdr.Logger] INFORMATIONAL *********** Exception
occurred ************ at 6:23 PM on Feb 21, 2006
     [exec] java.lang.Exception: mofId:
2372460E-9DFC-11DA-B44A-7DF378C9AA77:0000000000000BD9, class:
org.netbeans.jmi.javamodel.Annotation$Impl
     [exec]     at
org.netbeans.mdr.handlers.InstanceHandler.refDelete(InstanceHandler.java:307)
     [exec]     at
org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement.initOrCreate(MetadataElement.java:1309)
     [exec] [catch] at
org.netbeans.modules.javacore.jmiimpl.javamodel.MetadataElement.createChildrenList(MetadataElement.java:416)
.....

AND
     [exec] INFORMATIONAL *********** Exception occurred ************ at 6:23 PM
on Feb 21, 2006
     [exec] javax.jmi.reflect.InvalidObjectException: Object with MOFID
2372460E-9DFC-11DA-B44A-7DF378C9AA77:0000000000000BD9 no longer exists, class:
org.netbeans.jmi.javamodel.Annotation$Impl
     [exec]     at
org.netbeans.mdr.handlers.BaseObjectHandler._getDelegate(BaseObjectHandler.java:359)
     [exec]     at
org.netbeans.modules.javacore.jmiimpl.javamodel.DeferredAttrList.clearAttribComposite(DeferredAttrList.java:71)
.....

The interesting thing is that the annotation is still generated.

So, remaining items to be solved:
1) stack traces above
2) Can I make it wrap somehow?  Right now it all comes as one long line
3) How can I skip the value= for the NamedQueries annotation?  It is the default
and redundant and I would prefer to generate without it.
Comment 8 Pavel Buzek 2006-02-22 03:32:07 UTC
Rochelle:
#1 is for Pavel Flaska
#2 I do not see any way. I think this is not anything we should need to do, it
is a bug/enhancement for the code generator. So I suggest you integrate the code
as is and file an issue for javacore.
#3 I was thinking about the same (when I added the generation of @Temporal()
recently) and I figured that if I just pass and empty String to the
JMIGenerationUtil method instead of "value" it skips the value=. Sorry for
missleading you when I told you to use "value" :-).
Comment 9 Pavel Flaska 2006-02-22 13:32:03 UTC
#1) I'm not sure what causes exception. Please, provide steps, I will try to
reproduce it. I didn't see any problem in your code, I will try to debug it. IOE
is often caused by incorrectly generated source or when there are mdr calls
outside the mdr transaction. Unfortunately, it does not seem to be this case
IMO. IOE is consequence of some problem, but the exception itself does not say
much about the source. That is the reason why I want to step, stacktrace itself
does not help me to much.
#2) There is no way how to do that. Current generator is part of java/javacore
and only works with basic editor settings, e.g. where to place {, how many
spaces when indenting etc. There is too much work to create and respect
different indentation/wrapping settings. It is possible to create hot fixes for
some of cases, if it is big problem.
#3) Exactly as Pavel wrote.

Comment 10 Rochelle Raccah 2006-02-22 19:52:11 UTC
1) Today I can't reproduce it =).  So, can you merge the fix to the release55
branch?
2) I will file a separate RFE for this.
3) Empty string works.
Comment 11 Pavel Buzek 2006-02-22 21:10:54 UTC
I merged the fixed into release55. Please verify, Rochelle.
Comment 12 Rochelle Raccah 2006-02-22 23:24:21 UTC
Merged fix in branch is working.

I filed issue 72956 for #2.
Comment 13 Pavel Buzek 2006-02-23 00:09:04 UTC
fixed by Pavel Flaska
Comment 14 Pavel Buzek 2006-02-23 00:10:05 UTC
confirmed by Rochelle
Comment 15 Quality Engineering 2007-09-20 11:49:01 UTC
Reorganization of java component