Bug 582107 - Duplicated annotations when weaving methods with same name and same number of parameters
Summary: Duplicated annotations when weaving methods with same name and same number of...
Status: CLOSED MOVED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.9.7   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-22 09:22 EDT by Simon Urli CLA
Modified: 2023-06-22 10:26 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Urli CLA 2023-06-22 09:22:33 EDT
We discovered that apparently weaving two methods with same name and same number of parameters automatically leads to putting annotations of the first method to both the first and second method in the generated class, removing the possible existing annotations for it. 

So in our case we have an aspect file containing two methods: 
```
    @Deprecated(since = "2.2M2")
    public void XWikiDocument.rename(String newDocumentName, XWikiContext context) throws XWikiException
    {
        // Do stuff
    }

    @Deprecated(since = "12.5RC1")
    public void XWikiDocument.rename(DocumentReference newReference, XWikiContext context) throws XWikiException
    {
        // Do other stuff
    }
```

The obtained bytecode contains:
```
    @Deprecated(since = "2.2M2")
    public void rename(String newDocumentName, XWikiContext context) throws XWikiException
    {
        // Do stuff
    }

    @Deprecated(since = "2.2M2")
    public void rename(DocumentReference newReference, XWikiContext context) throws XWikiException
    {
        // Do other stuff
    }
```

When trying to understand the behaviour, I added another annotation to the first method: 
```
    @Deprecated(since = "2.2M2")
    @javax.validation.constraints.Size(message = "toto")
    public void XWikiDocument.rename(String newDocumentName, XWikiContext context) throws XWikiException
    {
        // Do stuff
    }

    @Deprecated(since = "12.5RC1")
    public void XWikiDocument.rename(DocumentReference newReference, XWikiContext context) throws XWikiException
    {
        // Do other stuff
    }
```

And I obtained:
```
    @Deprecated(since = "2.2M2")
    @javax.validation.constraints.Size(message = "toto")
    public void rename(String newDocumentName, XWikiContext context) throws XWikiException
    {
        // Do stuff
    }

    @Deprecated(since = "12.5RC1")
    @javax.validation.constraints.Size(message = "toto")
    public void rename(DocumentReference newReference, XWikiContext context) throws XWikiException
    {
        // Do other stuff
    }
```

Note that we don't have a method called `rename` with 2 parameters in the original `XWikiDocument.java`.
Comment 1 Simon Urli CLA 2023-06-22 09:31:47 EDT
Sorry I made a wrong copy paste, the latest bytecode I obtain is the following:
```
    @Deprecated(since = "2.2M2")
    @javax.validation.constraints.Size(message = "toto")
    public void rename(String newDocumentName, XWikiContext context) throws XWikiException
    {
        // Do stuff
    }

    @Deprecated(since = "2.2M2")
    @javax.validation.constraints.Size(message = "toto")
    public void rename(DocumentReference newReference, XWikiContext context) throws XWikiException
    {
        // Do other stuff
    }
```

So same annotations on both methods
Comment 2 Simon Urli CLA 2023-06-22 09:36:31 EDT
Also we're using AspectJ 1.9.19 but couldn't find it for the ticket version.
Comment 3 Alexander Kriegisch CLA 2023-06-22 10:26:14 EDT
Duplicatte of https://github.com/eclipse-aspectj/aspectj/issues/246, we will discuss it there.