@@ -1758,15 +1758,14 @@ private static AbstractPolyglotImpl loadAndValidateProviders(Iterator<? extends
1758
1758
}
1759
1759
impls .add (found );
1760
1760
}
1761
- Collections .sort (impls , Comparator .comparing (AbstractPolyglotImpl ::getPriority ));
1762
- Version polyglotVersion = Boolean .getBoolean ("polyglotimpl.DisableVersionChecks" ) ? null : getPolyglotVersion ();
1763
- AbstractPolyglotImpl prev = null ;
1764
- for (AbstractPolyglotImpl impl : impls ) {
1765
- if (impl .getPriority () == Integer .MIN_VALUE ) {
1766
- // disabled
1767
- continue ;
1768
- }
1769
- if (polyglotVersion != null ) {
1761
+ /*
1762
+ * Verifies the Polyglot and Truffle API versions before sorting polyglot implementations.
1763
+ * This is necessary because AbstractPolyglotImpl#getPriority, which is used during sorting,
1764
+ * may already depend on compatible API versions and could trigger incompatibility issues.
1765
+ */
1766
+ if (!Boolean .getBoolean ("polyglotimpl.DisableVersionChecks" )) {
1767
+ Version polyglotVersion = getPolyglotVersion ();
1768
+ for (AbstractPolyglotImpl impl : impls ) {
1770
1769
String truffleVersionString = impl .getTruffleVersion ();
1771
1770
Version truffleVersion = truffleVersionString != null ? Version .parse (truffleVersionString ) : Version .create (23 , 1 , 1 );
1772
1771
if (!polyglotVersion .equals (truffleVersion )) {
@@ -1794,6 +1793,14 @@ private static AbstractPolyglotImpl loadAndValidateProviders(Iterator<? extends
1794
1793
throw new IllegalStateException (errorMessage .toString ());
1795
1794
}
1796
1795
}
1796
+ }
1797
+ Collections .sort (impls , Comparator .comparing (AbstractPolyglotImpl ::getPriority ));
1798
+ AbstractPolyglotImpl prev = null ;
1799
+ for (AbstractPolyglotImpl impl : impls ) {
1800
+ if (impl .getPriority () == Integer .MIN_VALUE ) {
1801
+ // disabled
1802
+ continue ;
1803
+ }
1797
1804
impl .setNext (prev );
1798
1805
try {
1799
1806
impl .setConstructors (APIAccessImpl .INSTANCE );
0 commit comments