Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Handling in proxyNameAndBasePath() Method #53

Open
ezetina86 opened this issue Feb 21, 2024 · 0 comments
Open

Exception Handling in proxyNameAndBasePath() Method #53

ezetina86 opened this issue Feb 21, 2024 · 0 comments

Comments

@ezetina86
Copy link

ezetina86 commented Feb 21, 2024

I've noticed an issue with the proxyNameAndBasePath() method in StringUtils.java class that can cause an IndexOutOfBoundsException. This exception is thrown if the URL does not contain the / character. For example when creating a bundle from a wsdl file in the same directory.

Feb 21, 2024 9:12:36 AM com.apigee.proxywriter.GenerateProxy begin
SEVERE: begin -1, end 2, length 7
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin -1, end 2, length 7
	at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
	at java.base/java.lang.String.substring(String.java:1874)
	at com.apigee.utils.StringUtils.proxyNameAndBasePath(StringUtils.java:41)
	at com.apigee.proxywriter.GenerateProxy.getWSDLDetails(GenerateProxy.java:2358)
	at com.apigee.proxywriter.GenerateProxy.begin(GenerateProxy.java:2889)
	at com.apigee.proxywriter.GenerateProxy.main(GenerateProxy.java:3206)

Here the code in question:

public static KeyValue<String, String> proxyNameAndBasePath(String url) {
...
int beginIndex = lowercaseUrl.lastIndexOf("/");
map = new KeyValue<String,String>(url.substring(beginIndex+1, endIndex), url.substring(beginIndex, endIndex).toLowerCase());
...
}

Steps to Reproduce

The issue occurs when the provided URL does not contain a "/", such as: "my_fille.wsdl"

java -jar wsdl2apigee-1.0.0-jar-with-dependencies.jar -wsdl=my_fille.wsdl

Suggested Solution

The proxyNameAndBasePath() method can be updated to handle cases where the "/" character does not exist in the provided URL. When the lastIndexOf("/") method returns -1, beginIndex should be set to 0.

public static KeyValue<String, String> proxyNameAndBasePath(String url) {
...
int beginIndex = lowercaseUrl.lastIndexOf("/");
if (beginIndex == -1) {
   beginIndex = 0; // Set to 0 if "/" is not found
} else {
   beginIndex++; // Skipping "/"
}
...
}

This will prevent the IndexOutOfBoundsException from being thrown by the substring() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant