Software Product Line (SPL) aims to reduce development costs and time while improving quality, but the complexity and involvement of multiple design teams often lead to defects and delays. Detecting and resolving defects in large-scale industrial SPLs remains a significant research area. This study proposes a hybrid approach that combines the Harris Hawks Optimization (HHO) algorithm with stacking-based ensemble learning for defect detection in SPLs. Enhanced by the Chaos Optimization Algorithm (COA) to avoid local optima and improve accuracy, the approach is evaluated on two datasets, LVAT and NASA, This study incorporates four datasets from each of these repositories. The experiment results show that the proposed method achieves detection accuracy rates of 92.7%, 91.1%, 96.3%, 98.4% for the LTS1, LTM2, LTL3, LTV4 and 97.91%, 99.01%, 94.21%, 90.93% for the CM1, JM1, KC1, PC1. Statistical tests confirm that this method offers superior accuracy and faster convergence compared to existing methods.