tkobayas opened a new issue, #7252: URL: https://github.com/apache/incubator-kie/issues/7252
## Description In the executable model, a DRL annotation written with its Java name (for example `@Role` or `@Expires`) is silently ignored when the `declare` block redeclares an existing Java class. The classic compiler applies it correctly. Capitalized names are not documented for the default language level, where the docs only show the lowercase form. However, the classic compiler resolves them, and `DRL6_STRICT` requires them. Separated from [#7211](https://github.com/apache/incubator-kie/issues/7211), which covers annotation values such as `@role(FACT)` and `@role(EVENT)`. The fix for that issue does not address the cases below. ## Reproduction Java class: ```java @Role(Role.Type.EVENT) @Expires("10s") public class MyEvent { } ``` DRL: ```drl declare MyEvent @Role(FACT) @Expires(5s) end ``` Inspect `TypeDeclaration`: - Classic compiler: `role = FACT`, expiration offset 5000 (correct) - Executable model: `role = EVENT`, expiration offset 10000 (incorrect, the DRL annotations are ignored) ## Observed behavior Measured on `STANDARD_FROM_DRL` and `PATTERN_DSL` at commit `cfadb727e77`. Default language level (DRL6): | Target | DRL | Classic | Executable model | |---|---|---|---| | Java class with `@Role(EVENT)` | `@Role(FACT)` | FACT | EVENT (ignored) | | Plain Java class | `@Role(EVENT)` | EVENT | FACT (ignored) | | Java class with `@Expires("10s")` | `@Expires(5s)` | 5000 | 10000 (ignored) | | New declared type | `@Role(EVENT)` | EVENT | EVENT | | New declared type | `@Expires(5s)` | 5000 | 5000 | | New declared type | `@Role(Role.Type.EVENT)` | EVENT | compile error: `ROLE cannot be resolved or is not a field` | `DRL6_STRICT`, with the annotation placed before `declare`: | Target | DRL | Classic | Executable model | |---|---|---|---| | Plain Java class | `@Role(Role.Type.EVENT)` | EVENT | FACT (ignored) | | Java class with `@Role(EVENT)` | `@Role(Role.Type.FACT)` | FACT | EVENT (ignored) | | Plain Java class | `@role(event)` | error: `Unknown annotation: role` | EVENT (accepted) | | Java class with `@Expires("10s")` | `@Expires("5s")` | 5000 | error: `Error parsing time string: [ "5s" ]` | ## Cause For a redeclared Java class, `POJOGenerator.processTypeMetadata()` emits `ann.getName()` exactly as written in the DRL. `TypeDeclarationUtil.wireMetaTypeAnnotations()` then matches it with a case-sensitive `switch` on lowercase names such as `"role"` and `"expires"`, so `"Role"` and `"Expires"` fall through to the custom metadata branch. New declared types take a different path. `DescrAnnotationDefinition.fromDescr()` lowercases the name, so capitalized names work there. The `@Role(Role.Type.EVENT)` compile error on that path appears to come from `DescrAnnotationDefinition.parseValue()`, which prefixes `Role.Type.` to the uppercased value without handling an already qualified one. ## Expected behavior The executable model should treat these annotations like the classic compiler does: - Redeclaring a Java class with `@Role` or `@Expires` should take effect. - `DRL6_STRICT` should accept and reject the same annotations in both models. `@Timestamp`, `@Duration`, `@PropertyReactive`, `@ClassReactive` and `@PropertyChangeSupport` go through the same `switch`, so they should be checked too. They were not measured. ## Additional context `StrictAnnotationTest` does not cover the executable model, so `DRL6_STRICT` has no executable model coverage there. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
