You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "gitgabrio (via GitHub)" <gi...@apache.org> on 2024/03/21 08:28:48 UTC
[I] Fix ChangeSetBuilder.diffDescrs method [incubator-kie-issues]
gitgabrio opened a new issue, #1026:
URL: https://github.com/apache/incubator-kie-issues/issues/1026
The [ChangeSetBuilder.diffDescr](https://github.com/apache/incubator-kie-drools/blob/4004fe9bf745c5eae18223cd1d3a42d8efd4566e/drools-compiler/src/main/java/org/drools/compiler/kie/util/ChangeSetBuilder.java#L223) is inherently frail and error prone.
Its signarture receives two byte arrays and two Lists of generics `BaseDescr`
```java
private static <T extends BaseDescr> void diffDescrs(byte[] ob, byte[] cb,
ResourceChangeSet pkgcs,
List<T> odescrs, List<T> cdescrs,
ResourceChange.Type type, DescrNameConverter<T> descrNameConverter)
```
At line [239-240](https://github.com/apache/incubator-kie-drools/blob/4004fe9bf745c5eae18223cd1d3a42d8efd4566e/drools-compiler/src/main/java/org/drools/compiler/kie/util/ChangeSetBuilder.java#L240) the first element of the first collection is picked up and checked if there is a match
```java
for( Iterator<T> it = odescrs.iterator(); it.hasNext(); ) {
T ord = it.next();
if( descrNameConverter.getName(ord).equals( cName ) ) {
```
and then, at line [247](https://github.com/apache/incubator-kie-drools/blob/4004fe9bf745c5eae18223cd1d3a42d8efd4566e/drools-compiler/src/main/java/org/drools/compiler/kie/util/ChangeSetBuilder.java#L247), the informations from such object are used to manage (copy) the first byte array (similar thing happen for second array and second List)
```java
new String(Arrays.copyOfRange(ob, ord.getStartCharacter(), ord.getEndCharacter())),new String(Arrays.copyOfRange(cb, crd.getStartCharacter(), crd.getEndCharacter())) )
```
That implicitily requires that the `ord` object already contain correct informations about the `byte[] ob` (same goes true for `crd` and `byte[] cb`), that is not enforced in any way by the method itslef.
So, this method is inherently frail, because it requires that two completely independent objects are somehow "synchronized" by the calling code.
This has been unveiled by this [PR/modification ](https://github.com/apache/incubator-kie-drools/pull/5794)
```java
populateStartEnd(ruleDescr, ctx);
```
that clearly demonstrate this need.
In abstract way, the solution should be to create one single object that contains the `BaseDescr` (`T ord`) and the `byte[]` it refers to, so that the two would always be inherently in sync.
@mariofusco @tkobayas @baldimir @yesamer
--
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: commits-unsubscribe@kie.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Fix ChangeSetBuilder.diffDescrs method [incubator-kie-issues]
Posted by "mariofusco (via GitHub)" <gi...@apache.org>.
mariofusco commented on issue #1026:
URL: https://github.com/apache/incubator-kie-issues/issues/1026#issuecomment-2011681087
@gitgabrio I'm giving a look at that method but in all honesty at the moment I'm not understanding where is the problem. Is there a failing test case that I could try? Alternatively if you prefer we can have a quick call about it.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Fix ChangeSetBuilder.diffDescrs method [incubator-kie-issues]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio closed issue #1026: Fix ChangeSetBuilder.diffDescrs method
URL: https://github.com/apache/incubator-kie-issues/issues/1026
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Fix ChangeSetBuilder.diffDescrs method [incubator-kie-issues]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on issue #1026:
URL: https://github.com/apache/incubator-kie-issues/issues/1026#issuecomment-2011687262
Thanks @mariofusco I would prefer to have a call, whenever you have time: it would be easier to me to explain and maybe also understand if some of my assumptions are wrong.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Fix ChangeSetBuilder.diffDescrs method [incubator-kie-issues]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on issue #1026:
URL: https://github.com/apache/incubator-kie-issues/issues/1026#issuecomment-2012972377
@baldimir @yesamer @tkobayas
@mariofusco helped me to better understand the code (please correct me if something is wrong)
The important details are:
1. a BaseDescr (may) represent a part of a bigger one; if we (ideally) translate all that to `String`, we may think that the former is a "substring" of the latter, and the `startCharacter` and `endCharacter` define its position
2. that specific method is used to verify if a given "rule" has changed, so the `byte[]` parameters are the string representation of the same rule at two different moments;
3. the logic of this method is to extract the substring that represent the `BaseDescr` from both the new and old string representation of the rule, and compare them; the `startCharacter` and `endCharacter` are used to point to correct boundaries
4. the only point that I still see a little bit brittle is that the population of `startCharacter` and `endCharacter` has to be done explicitily/manually, and IIUC there are different places where this happen; it could be an improvement if, instead, those values are automaticaly set/updated while the BaseDecr is instantiated/populated, but I have no clear idea of the feasibility
Thanks again @mariofusco for explenation!
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [I] Fix ChangeSetBuilder.diffDescrs method [incubator-kie-issues]
Posted by "tkobayas (via GitHub)" <gi...@apache.org>.
tkobayas commented on issue #1026:
URL: https://github.com/apache/incubator-kie-issues/issues/1026#issuecomment-2014280044
FYI,
> the only point that I still see a little bit brittle is that the population of startCharacter and endCharacter has to be done explicitily/manually, and IIUC there are different places where this happen; it could be an improvement if, instead, those values are automaticaly set/updated while the BaseDecr is instantiated/populated, but I have no clear idea of the feasibility
I will consider it in this issue: https://github.com/apache/incubator-kie-drools/issues/5798
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org