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

WsImport.doMain() not closing binding file upon subsequent invocations #215

Closed
PhilSladen opened this issue Apr 13, 2021 · 14 comments · Fixed by #243 or #244
Closed

WsImport.doMain() not closing binding file upon subsequent invocations #215

PhilSladen opened this issue Apr 13, 2021 · 14 comments · Fixed by #243 or #244

Comments

@PhilSladen
Copy link

PhilSladen commented Apr 13, 2021

Calling WsImport.doMain(new String[] {"-keep", "-Xnocompile", "-p", "genTypesPkg", "-B-npa",
"-d", < path to temp dir>, "-b", < binding file>});

The first time it closes the binding file but upon subsequent invocations it appears to keep the binding file open because it is not possible to delete the file until the JVM is shutdown. Seems to happen with even the simplest WSDL. Binding file contents: < bindings xmlns="https://jakarta.ee/xml/ns/jaxws\">< enableWrapperStyle>false< /enableWrapperStyle>< /bindings>

@lukasj
Copy link
Member

lukasj commented Apr 13, 2021

version, please. Repro case/test would help too.

@PhilSladen
Copy link
Author

3.0.0

@aserkes
Copy link

aserkes commented Apr 21, 2021

I cannot reproduce the problem. Any additional information (test/case) would be helpful.

@PhilSladen
Copy link
Author

package issues;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.xml.sax.SAXParseException;

import com.sun.tools.ws.wscompile.WsimportTool;

public class Issue215 {
private static final String TEMP_DIR_PREFIX = "slurpTmp";
private static final String BINDING_FILE_PREFIX = "slurp";
private static final String BINDING_FILE_POSTFIX = "bindingFile.xml";
private static final String TYPES_PKG = "genTypesPkg";

public static void main(String args[]) throws Exception {
	runWsImport();
	runWsImport();
	Thread.sleep(60000); // during this time, unable to delete the 2nd binding file
}

public static void runWsImport() throws Exception {
	Path tmpDir = null;
	File bindingFile = null;
	try {
		tmpDir = Files.createTempDirectory(TEMP_DIR_PREFIX);
		bindingFile = createBindingFile();
		new MyWsImportTool().run(new String[] {"-keep", "-Xnocompile", "-p", TYPES_PKG, "-B-npa",
				"-d", tmpDir.toAbsolutePath().toString(), "-extension", "-b",
				bindingFile.getAbsolutePath(), "simple.wsdl"});
		// Process the Java classes...
	} finally {
		if (tmpDir != null) {
			deleteDirectory(tmpDir.toFile(), true);
		}
		if (bindingFile != null) {
			// TODO: Currently fails on subsequent call to MyWsImportTool().run()
			// Work-around calls cleanUpBindingFiles() upon startup.
			System.out.println("bindingFile=" + bindingFile.getAbsolutePath() + ", delete()=" + bindingFile.delete());
		}
	}
}

// Local version of WsimportTool so that it logs directly to our logger.
//
private static class MyWsImportTool extends WsimportTool {
	public MyWsImportTool() {
		super(System.out);
	}

	public boolean run(String[] args) {
		ImportListener listener = new ImportListener();
		Receiver receiver = new Receiver(listener);
		return super.run(args, listener, receiver);
	}

	private class ImportListener extends Listener {
		@Override
		public void message(String msg) {}
		@Override
		public void error(SAXParseException exception) {
			System.out.println(exception.getMessage());
		}
		@Override
		public void fatalError(SAXParseException exception) {
			System.out.println(exception.getMessage());
		}
		@Override
		public void warning(SAXParseException exception) {
			System.out.println(exception.getMessage());
		}
		@Override
		public void debug(SAXParseException exception) {
			System.out.println(exception.getMessage());
		}
		@Override
		public void info(SAXParseException exception) {
			System.out.println(exception.getMessage());
		}
	}
}

private static File createBindingFile() throws IOException {
	String bindingXml = "<bindings xmlns=\"https://jakarta.ee/xml/ns/jaxws\"><enableWrapperStyle>false</enableWrapperStyle></bindings>";
	File bindingFile = File.createTempFile(BINDING_FILE_PREFIX, BINDING_FILE_POSTFIX);
	FileWriter out = new FileWriter(bindingFile);
	out.write(bindingXml);
	out.close();
	return bindingFile;
}

private static boolean deleteDirectory(File dir, boolean log) {
	for (File file : dir.listFiles()) {
		if (file.isDirectory()) {
			deleteDirectory(file, log);
		} else if (!file.delete()) {
			if (log) {
				System.out.println("Failed to delete " + file);
			}
		}
	}
	boolean success;
	if (!(success=dir.delete())) {
		if (log) {
			System.out.println("Failed to delete " + dir);
		}
	}
	return success;
}

}

@lukasj
Copy link
Member

lukasj commented Apr 23, 2021

Operating systems do differ in file locking, so I assume this is on Windows. Can you confirm?

@PhilSladen
Copy link
Author

PhilSladen commented Apr 23, 2021

Windows 10 Home, 64 bit, OS build 19042.928. I am also attaching contents of "simple.wsdl", referred to in the reproduction code

@PhilSladen
Copy link
Author

simple.wsdl.txt

@aserkes
Copy link

aserkes commented May 10, 2021

I checked wscompile and did not find any issue that can cause the problem described in the bug.
I could reproduce the bug only in Windows and if I added to the code System.gc() before bindingFile.delete() the file always was deleted.
So I think the problem is not related to the wscompile.

lukasj added a commit that referenced this issue Jun 4, 2021
…cations

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
@lukasj
Copy link
Member

lukasj commented Jun 4, 2021

can you try 3.0.2-SNAPSHOT and let me know if the issue is gone, please?

@aserkes
Copy link

aserkes commented Jun 4, 2021

The issue is gone.

lukasj added a commit that referenced this issue Jun 4, 2021
…cations

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
(cherry picked from commit 3ff59c8)
@PhilSladen
Copy link
Author

PhilSladen commented Jun 7, 2021 via email

@lukasj
Copy link
Member

lukasj commented Jun 7, 2021

@PhilSladen
Copy link
Author

I tested with jars from the 3.0.2-SNAPSHOT link just provided and the issue appears to have been fixed. Many thanks.

@lukasj
Copy link
Member

lukasj commented Jun 7, 2021

great, thanks for checking!

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