How to fix lint ‘constructor ZipFile(File!)’ is deprecated. Deprecated in Javakotlin(DEPRECATION)

  Kiến thức lập trình

In a kotlin codebase, I’m getting the following lint:

'constructor ZipFile(File!)' is deprecated. Deprecated in Javakotlin(DEPRECATION)

for the following minimal code (I’ve removed everything but relevant lines)

import org.apache.commons.compress.archivers.zip.ZipFile
// snip
val tempFile = File.createTempFile("test","file")
val zipFile = ZipFile(tempFile)

The docs state I should “Use ZipFile.Builder.get()” but how do I do this? I’m new to Kotlin/Java and I struggle reading the style of docs used here.

2

I figured it out in the end, by replacing the line:

val zipFile = ZipFile(tempFile)

with

val zipFile = ZipFile.builder()
                .setFile(tempFile)
                .setUseUnicodeExtraFields(true)
                .get()

I’m not sure whether the .setUseUnicodeExtraFields(true) is a behaviour change or not – it probably doesn’t matter in most cases, but this might be a source for differences in behaviour.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website Kho Theme wordpress Kho Theme WP Theme WP

LEAVE A COMMENT