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: [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]
