# Problem using accessor properties in Bnd macro expansion

**URL:** <https://bnd.discourse.group/t/problem-using-accessor-properties-in-bnd-macro-expansion/285>\
**Category:** GENERAL\
**Created:** [January 22, 2023, 2:32pm UTC](https://bnd.discourse.group/t/problem-using-accessor-properties-in-bnd-macro-expansion/285 "2023-01-22T14:32:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisr3](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/chrisr3/32/58_2.png) [@chrisr3](https://bnd.discourse.group/u/chrisr3)\
**Post date:** [January 22, 2023, 2:32pm UTC](https://bnd.discourse.group/t/problem-using-accessor-properties-in-bnd-macro-expansion/285/1 "2023-01-22T14:32:34Z")

</div>

Hi,

I am using Bnd 6.4.0 and have written a custom annotation like this:

```java
@Header(name = "My-Foo", value = "${#value}")
@Target(PACKAGE)
@Retention(CLASS)
public @interface MyFoo {
    String value();
}

```

However, when I apply this annotation to one of my `package-info.java` files, Bnd does not process its macro as I expect, and I always end up with:

```java
My-Foo: ${#value}

```

in my bundle’s manifest. I have no such difficulty using macros like `${@package}`. Can anyone suggest what might be going wrong please?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![chrisr3](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/chrisr3/32/58_2.png) [@chrisr3](https://bnd.discourse.group/u/chrisr3)\
**Post date:** [January 24, 2023, 11:26am UTC](https://bnd.discourse.group/t/problem-using-accessor-properties-in-bnd-macro-expansion/285/2 "2023-01-24T11:26:44Z")

</div>

Nothing but tumbleweed? 😯

I thought either I’d done something _obviously_ wrong (although AFAICT it [matches the documentation](https://bnd.bndtools.org/chapters/235-accessor-properties.html)), or Bnd is forgetting to expand the `#value` macro for some reason.

Cheers,  
Chris

Edit: In fact, I am starting to think that `${#value}` just isn’t processed for `@Header` annotations, despite `@Header` also being a “bundle annotation”.

---

<div class="post-metadata">

**Author:** ![chrisr3](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/chrisr3/32/58_2.png) [@chrisr3](https://bnd.discourse.group/u/chrisr3)\
**Post date:** [January 25, 2023, 9:57am UTC](https://bnd.discourse.group/t/problem-using-accessor-properties-in-bnd-macro-expansion/285/3 "2023-01-25T09:57:44Z")

</div>

OK, I’ve run out of time to pursue this issue further. But from what I can tell, Bnd creates an `aQute.bnd.osgi.Annotation` instance for the `Header` annotation, but does not populate its `elements` field with a `#value` key. And hence the `${#value}` macro cannot be expanded.

But “accessor properties” seem to work fine for the `@Requirement` annotation, so I must assume this is a bug in Bnd.

Cheers,  
Chris

---

<div class="post-metadata">

**Author:** ![pkriens](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/pkriens/32/3_2.png) [@pkriens](https://bnd.discourse.group/u/pkriens)\
**Post date:** [January 25, 2023, 2:43pm UTC](https://bnd.discourse.group/t/problem-using-accessor-properties-in-bnd-macro-expansion/285/4 "2023-01-25T14:43:10Z")

</div>

Sorry to leave you dangling. The answer is a bit disappointing, the `Header` meta annotation does not support access to the attributes of the annotated annotation (`MyFoo` in your example.)

See [the line](https://github.com/bndtools/bnd/blob/631f5ba25f3b28ea68855940b7b91523f4ed30dc/biz.aQute.bndlib/src/aQute/bnd/osgi/AnnotationHeaders.java#L390) that processes this. For `Header` we do not merge the attributes like we do for the others.

Not sure why this exception was made. When I merge the attributes in the same way, it works like a charm.

If you think this is important, you should file an issue then we can find out who made this choice.

---

<div class="post-metadata">

**Author:** ![chrisr3](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/chrisr3/32/58_2.png) [@chrisr3](https://bnd.discourse.group/u/chrisr3)\
**Post date:** [January 26, 2023, 9:17pm UTC](https://bnd.discourse.group/t/problem-using-accessor-properties-in-bnd-macro-expansion/285/5 "2023-01-26T21:17:08Z")

</div>

OK, thanks, I’ve raised [#5530](https://github.com/bndtools/bnd/issues/5530) for this.

From my perspective, the documentation clearly states that this works for bundle annotations, of which `@Header` is one. There is no mention of `@Header` being an exception to this.

Cheers,  
Chris
