GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TiffTools: unsafe method of creating DataHandle<Location> became pack… · scichains/scichains-maps@06329d3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pom.xml
  • src
    • main/java/net/algart/matrices/io/formats/tiff/bridges/scifio
      • TiffTools.java
    • test/java/net/algart/matrices/io/formats/tiff/bridges/scifio/tests/legacy
      • FileHandleGenericsBug.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pom.xml‎

Copy file name to clipboardExpand all lines: pom.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<dependency>
8080
<groupId>org.scijava</groupId>
8181
<artifactId>scijava-common</artifactId>
82-
<version>2.95.1</version>
82+
<version>2.96.0</version>
8383
</dependency>
8484
</dependencies>
8585
<build>
Collapse file

‎src/main/java/net/algart/matrices/io/formats/tiff/bridges/scifio/TiffTools.java‎

Copy file name to clipboardExpand all lines: src/main/java/net/algart/matrices/io/formats/tiff/bridges/scifio/TiffTools.java
+16-8Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -535,27 +535,35 @@ public static DataHandle<Location> getExistingFileHandle(Path file) throws FileN
535535
throw new FileNotFoundException("File " + file
536536
+ (Files.exists(file) ? " is not a regular file" : " does not exist"));
537537
}
538-
return getFileHandle(file);
538+
DataHandle<Location> fileHandle = getFileHandle(file);
539+
fileHandle.set(new BytesLocation(100));
540+
return fileHandle;
539541
}
540542

541-
public static DataHandle<Location> getFileHandle(Path file) {
543+
static DataHandle<Location> getFileHandle(Path file) {
542544
Objects.requireNonNull(file, "Null file");
543545
return getFileHandle(new FileLocation(file.toFile()));
544546
}
545547

548+
/**
549+
* Warning: you should never call {@link DataHandle#set(Object)} method of the returned result!
550+
* It can lead to unpredictable <tt>ClassCastException</tt>.
551+
*/
546552
@SuppressWarnings("rawtypes, unchecked")
547-
public static DataHandle<Location> getFileHandle(FileLocation fileLocation) {
553+
static DataHandle<Location> getFileHandle(FileLocation fileLocation) {
548554
Objects.requireNonNull(fileLocation, "Null fileLocation");
549-
FileHandle fileHandle = new FileHandle();
550-
fileHandle.set(fileLocation);
555+
FileHandle fileHandle = new FileHandle(fileLocation);
551556
return (DataHandle) fileHandle;
552557
}
553558

559+
/**
560+
* Warning: you should never call {@link DataHandle#set(Object)} method of the returned result!
561+
* It can lead to unpredictable <tt>ClassCastException</tt>.
562+
*/
554563
@SuppressWarnings("rawtypes, unchecked")
555-
public static DataHandle<Location> getBytesHandle(BytesLocation bytesLocation) {
564+
static DataHandle<Location> getBytesHandle(BytesLocation bytesLocation) {
556565
Objects.requireNonNull(bytesLocation, "Null bytesLocation");
557-
BytesHandle bytesHandle = new BytesHandle();
558-
bytesHandle.set(bytesLocation);
566+
BytesHandle bytesHandle = new BytesHandle(bytesLocation);
559567
return (DataHandle) bytesHandle;
560568
}
561569

Collapse file

‎src/test/java/net/algart/matrices/io/formats/tiff/bridges/scifio/tests/legacy/FileHandleGenericsBug.java‎

Copy file name to clipboard
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2017-2023 Daniel Alievsky, AlgART Laboratory (http://algart.net)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package net.algart.matrices.io.formats.tiff.bridges.scifio.tests.legacy;
26+
27+
import io.scif.SCIFIO;
28+
import io.scif.formats.tiff.TiffParser;
29+
import org.scijava.Context;
30+
import org.scijava.io.handle.DataHandle;
31+
import org.scijava.io.location.BytesLocation;
32+
import org.scijava.io.location.FileLocation;
33+
import org.scijava.io.location.Location;
34+
35+
import java.io.File;
36+
37+
public class FileHandleGenericsBug {
38+
public static void main(String[] args) {
39+
if (args.length < 1) {
40+
System.out.println("Usage:");
41+
System.out.println(" " + FileHandleGenericsBug.class.getName() + " some_tiff_file");
42+
return;
43+
}
44+
final File file = new File(args[0]);
45+
46+
Context context = new SCIFIO().getContext();
47+
TiffParser parser = new TiffParser(context, new FileLocation(file));
48+
DataHandle<Location> stream = parser.getStream();
49+
System.out.println("Successfully opened: " + stream.getLocation());
50+
51+
BytesLocation bytesLocation = new BytesLocation(1000);
52+
stream.set(bytesLocation); // - crash!! java.lang.ClassCastException
53+
54+
System.out.println("This operator will not be performed");
55+
context.close();
56+
}
57+
}

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.