You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following code, the method defined inside the inner record is not pulled up with its enclosing record.
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package recordast;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.Objects;
/**
*
* @author homberghp (Pieter van den Hombergh) {@code <your.name at your.org>}
*/
class School extends Institute {
Student[] students;
Employee[] teachers;
School(Student... students) {
assert students != null;
this.students = students;
}
record Teacher(String name, String... topics) implements Serializable, Cloneable {
}
record Student(int id, String name, LocalDate dob, String... grades) implements Serializable {
Student {
// ensure valid id
assert id > 0;
assert name != null && !name.isBlank();
assert dob.isAfter(LocalDate.EPOCH);
}
String gradesAsString() {
return Arrays.toString(grades);
}
}
class Employee<R> implements Serializable {
private final int id;
private final String name;
private final LocalDate dob;
Employee(int id, String name, LocalDate dob, R role) {
assert id > 0;
assert name != null;
assert dob.isAfter(LocalDate.EPOCH);
this.id = id;
this.name = name;
this.dob = dob;
}
@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + this.id;
hash = 71 * hash + Objects.hashCode(this.name);
hash = 71 * hash + Objects.hashCode(this.dob);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Employee other = (Employee) obj;
if (this.id != other.id) {
return false;
}
if (!Objects.equals(this.name, other.name)) {
return false;
}
return Objects.equals(this.dob, other.dob);
}
@Override
public String toString() {
return "Employee{" + "id=" + id + ", name=" + name + ", dob=" + dob + '}';
}
}
public static void main(String[] args) {
Student jan = new Student(123, "Jan", LocalDate.now(), "A", "D+");
School s = new School(jan);
System.out.println("s = " + s);
System.out.println("jan = " + jan + "grades" + jan.gradesAsString());
}
}
and
class Institute {
}
The problem may ly in the improper handling of the compact constructor, which may not contain a super
call.
Language / Project Type / NetBeans Component
java refactoring (java/refactoring.java)
How to reproduce
Try pull up e.g. Student member to super class Institute.
The compact constructor is miss formed.
Did this work correctly in an earlier version?
No / Don't know
Operating System
linux ubuntu 24.04 LTS
JDK
jdk 17 (the build platform for netbeans 25)
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
The problem occurs consistently.
I found the error while extending the tests on PR 8374
The test is on my branch issue7044a in my repo homberghp/netbeans.
If hope to work on a solution, because I may be the culprit.
Are you willing to submit a pull request?
Yes
The text was updated successfully, but these errors were encountered:
Apache NetBeans version
Apache NetBeans 25
What happened
In the following code, the method defined inside the inner record is not pulled up with its enclosing record.
and
The problem may ly in the improper handling of the compact constructor, which may not contain a super
call.
Language / Project Type / NetBeans Component
java refactoring (java/refactoring.java)
How to reproduce
Try pull up e.g. Student member to super class Institute.
The compact constructor is miss formed.
Did this work correctly in an earlier version?
No / Don't know
Operating System
linux ubuntu 24.04 LTS
JDK
jdk 17 (the build platform for netbeans 25)
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
The problem occurs consistently.
I found the error while extending the tests on PR 8374
The test is on my branch issue7044a in my repo homberghp/netbeans.
If hope to work on a solution, because I may be the culprit.
Are you willing to submit a pull request?
Yes
The text was updated successfully, but these errors were encountered: