@@ -57,7 +57,7 @@ public String getVersion() {
5757 public static List <String > getSupportedVersions () {
5858 try {
5959 return fetchSupportedVersions ();
60- } catch (Exception e ) {
60+ } catch (Exception e ) { //NOPMD - suppressed AvoidCatchingGenericException
6161 // Return an empty list or log the exception
6262 return List .of ();
6363 }
@@ -71,9 +71,9 @@ public static List<String> getSupportedVersions() {
7171 * @return List[String] containing supported version strings
7272 * @throws Exception if an error occurs during HTTP connection or JSON parsing
7373 */
74- public static List <String > fetchSupportedVersions () throws Exception {
75- String url = "https://repo.packagist.org/p2/magento/community-edition.json" ;
76- List <String > versions = new ArrayList <>();
74+ public static List <String > fetchSupportedVersions () throws Exception { //NOPMD - suppressed SignatureDeclareThrowsException
75+ final String url = "https://repo.packagist.org/p2/magento/community-edition.json" ;
76+ final List <String > versions = new ArrayList <>();
7777
7878 HttpURLConnection connection = null ;
7979 try {
@@ -82,8 +82,8 @@ public static List<String> fetchSupportedVersions() throws Exception {
8282 connection .setRequestMethod ("GET" );
8383 connection .setRequestProperty ("Accept" , "application/json" );
8484
85- if (connection .getResponseCode () != 200 ) {
86- throw new Exception (
85+ if (connection .getResponseCode () != 200 ) { //NOPMD - suppressed AvoidLiteralsInIfCondition
86+ throw new Exception ( //NOPMD - suppressed AvoidThrowingRawExceptionTypes
8787 "Failed to fetch data, HTTP response code: " + connection .getResponseCode ()
8888 );
8989 }
@@ -92,35 +92,30 @@ public static List<String> fetchSupportedVersions() throws Exception {
9292 try (BufferedReader reader = new BufferedReader (
9393 new InputStreamReader (connection .getInputStream ()))
9494 ) {
95- StringBuilder response = new StringBuilder ();
95+ final StringBuilder response = new StringBuilder ();
9696 String line ;
97- while ((line = reader .readLine ()) != null ) {
97+ while ((line = reader .readLine ()) != null ) { //NOPMD - suppressed AssignmentInOperand
9898 response .append (line );
9999 }
100100
101101 // Parse JSON for version data
102- JSONObject jsonResponse = new JSONObject (response .toString ());
103- JSONArray packageObject = jsonResponse
102+ final JSONObject jsonResponse = new JSONObject (response .toString ());
103+ final JSONArray packageObject = jsonResponse
104104 .getJSONObject ("packages" )
105105 .getJSONArray ("magento/community-edition" );
106106
107- for (Object o : packageObject ) {
108- JSONObject version = (JSONObject ) o ;
107+ for (final Object o : packageObject ) {
108+ final JSONObject version = (JSONObject ) o ;
109109 if (version == null ) {
110110 continue ;
111111 }
112- String versionstring = version .getString ("version" );
112+ final String versionstring = version .getString ("version" );
113113 if (versionstring == null ) {
114114 continue ;
115115 }
116116 versions .add (versionstring );
117117 }
118118 }
119- } catch (Exception e ) {
120- throw new Exception (
121- "Error fetching or parsing supported versions: " + e .getMessage (),
122- e
123- );
124119 } finally {
125120 if (connection != null ) {
126121 connection .disconnect ();
0 commit comments